最終更新:2019-03-01 (金) 04:14:10 (1880d)  

uinput
Top / uinput

User level driver support for input subsystem

ドキュメント (Linux 4.12~)

概要

.config

バージョン

  • UINPUT_VERSION? - uapi/linux/uinput.hで定義
    0.552015/08/13Linux 4.5add UI_DEV_SETUP, UI_ABS_SETUP?, UI_GET_VERSION? ioctl
    0.442014/09/01Linux 3.15update ff support for the changes in kernel interface
    add UI_GET_SYSNAME? ioctl
    0.332006/05/24Linux 2.6.19?add UINPUT_VERSION?
    0.22004/10/16added force feedback support
    added UI_SET_PHYS?
    0.12002/06/20first public version

デバイスファイル

ソースコード

イベントコード

有効化

  • modprobe uinput

uinput 0.5用のサンプル

変更点

使い方 (古いuinput 0.4のコード)

ひな形

  • #include <linux/input.h>
    #include <linux/uinput.h>
    ...
    
    int fd;
    
    fd = open("/dev/input/uinput", O_WRONLY | O_NONBLOCK);
    if(fd < 0) {
        ...
        exit(EXIT_FAILURE);
    }

どういうデバイスを作るか書き込み

  • 使用するinput_eventのtypeとcodeをあらかじめ書き込む。

ioctlの引数

  • UI_SET_EVBIT?
    • EV_SYN - used to separate input events into packets of input data changes occurring at the same moment in time.
    • EV_KEY - キーボードやマウスボタンなどのキー入力
    • EV_REL - マウスの動きやマウスホイールやジョグダイヤルなどの相対的な動き
    • EV_ABS - ジョイスティックの傾きやタッチパネルの入力やアクセルペダルなどの絶対的な動き
  • UI_SET_RELBIT?
  • UI_SET_ABSBIT?
  • UI_SET_MSCBIT?
  • UI_SET_LEDBIT?
  • UI_SET_SNDBIT?
  • UI_SET_FFBIT?
  • UI_SET_PHYS?
  • UI_SET_SWBIT?
  • UI_SET_PROPBIT?
    ioctl(fd, UI_SET_EVBIT, EV_REL);
    ioctl(fd, UI_SET_RELBIT, REL_X);
    ioctl(fd, UI_SET_RELBIT, REL_Y);
    
    ioctl(fd, UI_SET_EVBIT, EV_KEY);
    ioctl(fd, UI_SET_KEYBIT, KEY_D);

uinput_user_devの登録

  • struct uinput_user_dev device;
    //memset(&uidev, 0, sizeof(uidev));
    
    snprintf(device.name, UINPUT_MAX_NAME_SIZE, "uinput-sample");
    device.id.bustype = 0;//BUS_USBとか
    device.id.vendor  = 0;
    device.id.product = 0;
    device.id.version = 0;
    
    ret = write(ui_fd, &device, sizeof(device)) < sizeof(device));

デバイスの作成

  • UI_DEV_CREATE?
    ioctl(ui_fd, UI_DEV_CREATE, NULL);

イベント(input_event)の書き込み

  • struct input_event ev;
    
    memset(&ev, 0, sizeof(ev));
    
    ev.type = EV_KEY;
    ev.code = KEY_D;
    ev.value = 1;
    
    ret = write(fd, &ev, sizeof(ev))

Python

関連

参考