最終更新:2019-04-02 (火) 18:13:39 (1844d)  

input_event
Top / input_event

構造体 (uapi/linux/input.h)

//The event structure itself
struct input_event {
        struct timeval time;
        __u16 type;
        __u16 code;
        __s32 value;
};

input_event.type (EV_~)

  • 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 - ジョイスティックの傾きやタッチパネルの入力やアクセルペダルなどの絶対的な動き

input_event.code

  • Linux/キーコード
    • KEY_
      • KEY_A?
      • KEY_SPACE? - スペースキー
      • KEY_MUTE? - ミュートキー
  • BTN_LEFT - マウスの左ボタン
  • REL_X - マウス等のx軸方向の動き
  • ABS_X - タッチパネル等のx軸方向の位置、ジョイスティックのx軸方向の傾き

input_event.value?

  • キーが押されたのか離したのか、マウスなどがどのぐらい動いたのかなど、typeによって次のような意味を持つ

type == EV_KEYの場合

  • キーを押したときは1、離したときは0、オートリピートによる入力があったときは2

type == EV_RELの場合

  • 動いた量

type == EV_ABSの場合

  • 現在の値

関数 (linux/input.h)

  • drivers/input/input.c
    void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
    /**
     * input_event() - report new input event
     * @dev: device that generated the event
     * @type: type of the event
     * @code: event code
     * @value: value of the event
     *
     * This function should be used by drivers implementing various input
     * devices to report input events. See also input_inject_event().
     *
     * NOTE: input_event() may be safely used right after input device was
     * allocated with input_allocate_device(), even before it is registered
     * with input_register_device(), but the event will not reach any of the
     * input handlers. Such early invocation of input_event() may be used
     * to 'seed' initial state of a switch or initial position of absolute
     * axis, etc.
     */
    void input_event(struct input_dev *dev,
    		 unsigned int type, unsigned int code, int value)
    {
    	unsigned long flags;
    
    	if (is_event_supported(type, dev->evbit, EV_MAX)) {
    
    		spin_lock_irqsave(&dev->event_lock, flags);
    		add_input_randomness(type, code, value);
    		input_handle_event(dev, type, code, value);
    		spin_unlock_irqrestore(&dev->event_lock, flags);
    	}
    }
    EXPORT_SYMBOL(input_event);

ラッパー関数

関連

参考