现在的位置: 首页 > 综合 > 正文

[Linux Input]even-codes.txt input事件类型

2018年02月11日 ⁄ 综合 ⁄ 共 12732字 ⁄ 字号 评论关闭

The input protocol uses a map of types and codes to express input device values
to userspace. This document describes the types and codes and how and when they
may be used.

input协议使用类型和编码的图来向用户空间表示一个input设备的值。
这个文档就是描述这些类型和编码怎么使用,什么时候被使用。

A single hardware event generates multiple input events. Each input event
contains the new value of a single data item. A special event type, EV_SYN, is
used to separate input events into packets of input data changes occurring at
the same moment in time. In the following, the term "event" refers to a single
input event encompassing a type, code, and value.

一个单独的硬件事件产生多个input事件,每个input事件包含了一个新的单一数据项。
事件类型EV_SYN用来把同时产生的input事件分割成多个input数据包。在下面的描述中,
event表示包含了type,code,value的一个单一输入事件。

The input protocol is a stateful protocol. Events are emitted only when values
of event codes have changed. However, the state is maintained within the Linux
input subsystem; drivers do not need to maintain the state and may attempt to
emit unchanged values without harm. Userspace may obtain the current state of
event code values using the EVIOCG* ioctls defined in linux/input.h. The event
reports supported by a device are also provided by sysfs in
class/input/event*/device/capabilities/, and the properties of a device are
provided in class/input/event*/device/properties.

input协议是一个状态类的协议。只有当事件的编码值(codes)改变的时候才会提交一个事件。
然而,这个状态是由Linux的input子系统维护的。驱动不需要维护或者尝试提交一个没有改变的值
也不会对它造成伤害。用户空间可能使用定义在linux/input.h中的以EVIOCG*开头的这些ioctl来
获得了当前事件的编码值。
设备支持的事件报告可以在sysfs文件系统提供的class/input/event*/device/capabilities/获得,
设备的属性可以在class/input/event*/device/properties获得。

Types:
==========
Types are groupings of codes under a logical input construct. Each type has a
set of applicable codes to be used in generating events. See the Codes section
for details on valid codes for each type.

类型:
类型根据逻辑输入构成分组编码。每个类型有一个适合的编码用来表示一个事件。想要获得更多详细的关于
每个类型的编码的内容请看下面的Codes这一节。

* EV_SYN:
  - Used as markers to separate events. Events may be separated in time or in
    space, such as with the multitouch protocol.
* EV_SYN:
  - 用来标志一个分割事件。事件可能被从时间或者空间上分割,例如在多点出空的协议中。

* EV_KEY:
  - Used to describe state changes of keyboards, buttons, or other key-like
    devices.
* EV_KEY:
  - 用来描述键盘,按键或者其他键盘类的设备状态值改变。

* EV_REL:
  - Used to describe relative axis value changes, e.g. moving the mouse 5 units
    to the left.
* EV_REL:
  - 用来描述一个相对坐标值的改变。

* EV_ABS:
  - Used to describe absolute axis value changes, e.g. describing the
    coordinates of a touch on a touchscreen.
* EV_ABS:
  - 用来描述绝对坐标值的改变。例如描述一个触摸屏的坐标。

* EV_MSC:
  - Used to describe miscellaneous input data that do not fit into other types.
* EV_MSC:
  - 用来描述一个没有合适类型的杂项输入数据。

* EV_SW:
  - Used to describe binary state input switches.
* EV_SW:
  - 用来描述一个二态开关的状态。

* EV_LED:
  - Used to turn LEDs on devices on and off.
* EV_LED:
  - 用来控制LED等的开、关。

* EV_SND:
  - Used to output sound to devices.
* EV_SND:
  - 用来向设备输出声音。

* EV_REP:
  - Used for autorepeating devices.
* EV_REP:
  - 适用于自动重复设备。

* EV_FF:
  - Used to send force feedback commands to an input device.
* EV_FF:
  - 用于想一个输入设备强制发送反馈命令。

* EV_PWR:
  - A special type for power button and switch input.
* EV_PWR:
  - 电源开关或者按钮的特别输入类型。

* EV_FF_STATUS:
  - Used to receive force feedback device status.
* EV_FF_STATUS:
  - 用于接收设备强制反馈状态。

Codes:
==========
Codes define the precise type of event.

编码:
编码用于更精准地定义事件的类型。

EV_SYN:
----------
EV_SYN event values are undefined. Their usage is defined only by when they are
sent in the evdev event stream.

* SYN_REPORT:
  - Used to synchronize and separate events into packets of input data changes
    occurring at the same moment in time. For example, motion of a mouse may set
    the REL_X and REL_Y values for one motion, then emit a SYN_REPORT. The next
    motion will emit more REL_X and REL_Y values and send another SYN_REPORT.

EV_SYN:
EV_SYN事件值没有定义。只有当他们在evdev事件流发送的时候才被定义。
* SYN_REPORT:
  - 当同时发生输入数据改变时,SYN_REPORT用于同步和分割事件成为数据包。
举个例子,鼠标按下时同时会设置REL_X和REL_Y的值,然后发送SYN_REPORT。下次鼠标移动后
还会发送REL_X和REL_Y,再发送另外一个SYN_REPORT。
 
* SYN_CONFIG:
  - TBD

* SYN_MT_REPORT:
  - Used to synchronize and separate touch events. See the
    multi-touch-protocol.txt document for more information.
* SYN_MT_REPORT:
  - 用于同步和分离触摸事件。想了解更多请看multi-touch-protocol.txt。

* SYN_DROPPED:
  - Used to indicate buffer overrun in the evdev client's event queue.
    Client should ignore all events up to and including next SYN_REPORT
    event and query the device (using EVIOCG* ioctls) to obtain its
    current state.
* SYN_DROPPED:
  - 用于指示在evdev中的client的事件队列缓冲区溢出。Clinet会忽略所有事件而且包括
下一个SYN_REPORT事件。而且要查询设备(使用EVIOCG*的ioctls)去获取当前的状态。

EV_KEY:
----------
EV_KEY events take the form KEY_<name> or BTN_<name>. For example, KEY_A is used
to represent the 'A' key on a keyboard. When a key is depressed, an event with
the key's code is emitted with value 1. When the key is released, an event is
emitted with value 0. Some hardware send events when a key is repeated. These
events have a value of 2. In general, KEY_<name> is used for keyboard keys, and
BTN_<name> is used for other types of momentary switch events.

EV_KEY:
E_KEY事件采取KEY_<name>或者BTN_<name>的形式。举个例子,KEY_A用于描述键盘上的按键'A'。
当一个按键被按下时,一个按键的事件编码被设置为1且被提交。当一个按键释放的时候,会提交
一个0值。一些硬件当一个按键重复时发送一个值2.通常,KEY_<name>用于键盘按键。而BTN_<name>
用于开关事件类型。

A few EV_KEY codes have special meanings:
一些特别的EV_KEY编码含义

* BTN_TOOL_<name>:
  - These codes are used in conjunction with input trackpads, tablets, and
    touchscreens. These devices may be used with fingers, pens, or other tools.
    When an event occurs and a tool is used, the corresponding BTN_TOOL_<name>
    code should be set to a value of 1. When the tool is no longer interacting
    with the input device, the BTN_TOOL_<name> code should be reset to 0. All
    trackpads, tablets, and touchscreens should use at least one BTN_TOOL_<name>
    code when events are generated.
* BTN_TOOL_<name>:
  - 这类编码和触控板,触摸屏相关。这些设备可能使用手指,触摸屏或其他工具进行交互。
当使用这些工具的时候产所事件,相应的BTN_TOOL_<name>编码被置为1。当没有工具和输入设备
交互时,BTN_TOOL_<name>就会被置为0。当有事件发生时,所有的触摸板,触摸屏都应该使用至
少使用一个BTN_TOOL_<name>编码。

* BTN_TOUCH:
    BTN_TOUCH is used for touch contact. While an input tool is determined to be
    within meaningful physical contact, the value of this property must be set
    to 1. Meaningful physical contact may mean any contact, or it may mean
    contact conditioned by an implementation defined property. For example, a
    touchpad may set the value to 1 only when the touch pressure rises above a
    certain value. BTN_TOUCH may be combined with BTN_TOOL_<name> codes. For
    example, a pen tablet may set BTN_TOOL_PEN to 1 and BTN_TOUCH to 0 while the
    pen is hovering over but not touching the tablet surface.

* BTN_TOUCH:
    BTN_TOUCH用于触摸点。当一个输入工具被定义为有意义的物理触摸设备时。这个值必须被置为1。
有意义的物理接触可能是任何接触,或者它意味着有现实意义的接触。举个例子,当一个触摸板被触摸并
压力值到达某一个特定的值时,value可以设置为1。BTN_TOUCH可能和BTN_TOOL_<name>联合使用。
举个例子,当一个手写板的笔在手写板上盘旋但是没有接触到手写板板面时,设置BTN_TOOL_PEN为1,
BTN_TOUCH为0.

Note: For appropriate function of the legacy mousedev emulation driver,
BTN_TOUCH must be the first evdev code emitted in a synchronization frame.
注意:为了兼容以前老版本的mousedev模拟驱动,BTN_TOUCH必须在同步帧中作为第一个evdev编码被提交。

Note: Historically a touch device with BTN_TOOL_FINGER and BTN_TOUCH was
interpreted as a touchpad by userspace, while a similar device without
BTN_TOOL_FINGER was interpreted as a touchscreen. For backwards compatibility
with current userspace it is recommended to follow this distinction. In the
future, this distinction will be deprecated and the device properties ioctl
EVIOCGPROP, defined in linux/input.h, will be used to convey the device type.
注意:由于历史原因,一个带BTN_TOOL_FINGER和BTN_TOUCH的触摸设备在用户空间被当作触摸板,而
不使用BTN_TOOL_FINGER的类似触摸设备被认为是一个触摸屏。为了和当前用户空间向后兼容性,建议
遵守这一原则。可能以后这个特性可能会被取消失效而采用定义在linux/input.h的ioctl方法EVIOCGPROP
来传输设备的类型。

* BTN_TOOL_FINGER, BTN_TOOL_DOUBLETAP, BTN_TOOL_TRIPLETAP, BTN_TOOL_QUADTAP:
  - These codes denote one, two, three, and four finger interaction on a
    trackpad or touchscreen. For example, if the user uses two fingers and moves
    them on the touchpad in an effort to scroll content on screen,
    BTN_TOOL_DOUBLETAP should be set to value 1 for the duration of the motion.
    Note that all BTN_TOOL_<name> codes and the BTN_TOUCH code are orthogonal in
    purpose. A trackpad event generated by finger touches should generate events
    for one code from each group. At most only one of these BTN_TOOL_<name>
    codes should have a value of 1 during any synchronization frame.
* BTN_TOOL_FINGER,BTN_TOOL_DOUBLETAP,BTN_TOOL_TRIPLETAP,BTN_TOOL_QUADTAP:
  - 这些编码分别表示一个,两个,三个和四个手指在触摸板货触摸屏上交互。举个例子,
如果用户使用两个手指并在触摸板上移动想滚动显示屏幕上的内容时,在这期间BTN_TOOL_DOUBLETAP
应该被置为1。注意,所有的BTN_TOOL_<name>编码和BTN_TOUCH编码都用于正交。一个手指触摸事件
应该在这两个组中都产生一个事件编码。至少一个BTN_TOOL_<name>编码在同步帧中设置为1。

Note: Historically some drivers emitted multiple of the finger count codes with
a value of 1 in the same synchronization frame. This usage is deprecated.
注意:由于历史原因一些驱动在一个同步真中提交多个值为1的编码代表接触点个数。这种方法过时了。

Note: In multitouch drivers, the input_mt_report_finger_count() function should
be used to emit these codes. Please see multi-touch-protocol.txt for details.
注意:在多点触控的驱动中,input_mt_report_finger_count()函数应该 用于提交上面这写编码。
详细请看multi-touch-protocol.txt。

EV_REL:
----------
EV_REL events describe relative changes in a property. For example, a mouse may
move to the left by a certain number of units, but its absolute position in
space is unknown. If the absolute position is known, EV_ABS codes should be used
instead of EV_REL codes.
EV_REL:
EV_REL事件描述一个某种特性的相对的变化。举个例子,鼠标向左移动一些单位,但是他的绝对位置是
不知道的。如果想知道绝对位置,应该使用EV_ABS编码应该代替EV_REL编码。

A few EV_REL codes have special meanings:
一些有特别意义的EV_REL编码:

* REL_WHEEL, REL_HWHEEL:
  - These codes are used for vertical and horizontal scroll wheels,
    respectively.
* REL_WHEEL, REL_HWHEEL:
  - 这两个编码分别用于垂直和水平的滚轮。

EV_ABS:
----------
EV_ABS events describe absolute changes in a property. For example, a touchpad
may emit coordinates for a touch location.
EV_ABS:
EV_ABS事件描述某种特性的绝对变化。举个例子,一个触摸板会提交触摸位置的坐标。

A few EV_ABS codes have special meanings:
一些有特殊意义的EV_ABS编码:

* ABS_DISTANCE:
  - Used to describe the distance of a tool from an interaction surface. This
    event should only be emitted while the tool is hovering, meaning in close
    proximity of the device and while the value of the BTN_TOUCH  is 0. If
    the input device may be used freely in three dimensions, consider ABS_Z
    instead.
* ABS_DISTANCE:
  - 使用它来描述触摸工具与一个交互平面上的距离。这个事件仅仅在工具盘旋在触摸表面上,
意味着设备非常接近设置BTN_TOUCH为0。如果设备能自由的在三位空间运动,请考虑使用ABS_Z。

* ABS_MT_<name>:
  - Used to describe multitouch input events. Please see
    multi-touch-protocol.txt for details.
* ABS_MT_<name>:
  - 用于描述多点触控输入事件。详细请看multi-touch-protocol.txt

EV_SW:
----------
EV_SW events describe stateful binary switches. For example, the SW_LID code is
used to denote when a laptop lid is closed.
EV_SW:
EV_SW事件用于描述二状态开关。举个例子,SW_LID编码用于表示一个笔记本电脑盖子是否合上。

Upon binding to a device or resuming from suspend, a driver must report
the current switch state. This ensures that the device, kernel, and userspace
state is in sync.
当绑定一个设备或者从挂起状态恢复的时候,驱动必须报告但却的开关状态。保证设备,内核
和用户空间的同步。

Upon resume, if the switch state is the same as before suspend, then the input
subsystem will filter out the duplicate switch state reports. The driver does
not need to keep the state of the switch at any time.
恢复时(resume),如何开关状态和挂起之前相同,input子系统会过滤掉相同重复的开关状态报告。
设备不许要记住开关的任何状态。

EV_MSC:
----------
EV_MSC events are used for input and output events that do not fall under other
categories.
EV_MSC:
EV_MSC事件用于输入和输出都不属于其他类型的事件。

EV_LED:
----------
EV_LED events are used for input and output to set and query the state of
various LEDs on devices.
EV_LED:
EV_LED事件用于输入和输出的事件,设置和查询在设备上不同LEDS的状态

EV_REP:
----------
EV_REP events are used for specifying autorepeating events.
EV_REP:
EV_REP事件用于指定(指出)的重复事件。

EV_SND:
----------
EV_SND events are used for sending sound commands to simple sound output
devices.
EV_SND:
EV_SND事件用于给简单的声音输出设备发送声音命令。

EV_FF:
----------
EV_FF events are used to initialize a force feedback capable device and to cause
such device to feedback.
EV_FF:
EV_FF事件用于初始化一个有强制回馈能力的设备,并能引起这些设备的反馈。

EV_PWR:
----------
EV_PWR events are a special type of event used specifically for power
mangement. Its usage is not well defined. To be addressed later.
EV_PWR:
EV_PWR事件用于电源管理的特殊事件类型。它还没被定义。

Guidelines:
==========
The guidelines below ensure proper single-touch and multi-finger functionality.
For multi-touch functionality, see the multi-touch-protocol.txt document for
more information.
使用手册:
使用手册为了保证单点触控和多点触控的功能。想知道更多关于多点触控的功能,
请看multi-touch-protocol.txt。

Mice:
----------
REL_{X,Y} must be reported when the mouse moves. BTN_LEFT must be used to report
the primary button press. BTN_{MIDDLE,RIGHT,4,5,etc.} should be used to report
further buttons of the device. REL_WHEEL and REL_HWHEEL should be used to report
scroll wheel events where available.
鼠标:
当鼠标移动时必须上报REL_{X,Y}。BTN_LEFT用于报告主要的按键按下(鼠标左键?)。
BTN_{MIDDLE,RIGHT,4,5,etc.}应该用于报告设备其他的按键。REL_WHEEL和REL_HWHEEL用于报告
滚轮的事件。

Touchscreens:
----------
ABS_{X,Y} must be reported with the location of the touch. BTN_TOUCH must be
used to report when a touch is active on the screen.
BTN_{MOUSE,LEFT,MIDDLE,RIGHT} must not be reported as the result of touch
contact. BTN_TOOL_<name> events should be reported where possible.
触摸屏:
触摸屏上的触摸位置必须使用ABS_{X,Y}上报。当触摸屏有效的时候,必须使用BTN_TOUCH来
上报。不必使用BTN_{MOUSE,LEFT,MIDDLE,RIGHT}作为触摸结果上报。BTN_TOOL_<name>也
可以上报事件。

Trackpads:
----------
Legacy trackpads that only provide relative position information must report
events like mice described above.

Trackpads that provide absolute touch position must report ABS_{X,Y} for the
location of the touch. BTN_TOUCH should be used to report when a touch is active
on the trackpad. Where multi-finger support is available, BTN_TOOL_<name> should
be used to report the number of touches active on the trackpad.
触摸板:
以前的触摸板像鼠标报告事件那样只提供相对坐标的信息。

提供绝对坐标的触摸板必须使用ABS_{X,Y}来上报触摸信息。触摸有效时需要报告BTN_TOUCH,
使用BTN_TOOL_<name>上报触摸有效的触摸点数量。

Tablets:
----------
BTN_TOOL_<name> events must be reported when a stylus or other tool is active on
the tablet. ABS_{X,Y} must be reported with the location of the tool. BTN_TOUCH
should be used to report when the tool is in contact with the tablet.
BTN_{STYLUS,STYLUS2} should be used to report buttons on the tool itself. Any
button may be used for buttons on the tablet except BTN_{MOUSE,LEFT}.
BTN_{0,1,2,etc} are good generic codes for unlabeled buttons. Do not use
meaningful buttons, like BTN_FORWARD, unless the button is labeled for that
purpose on the device.code

手写板:
在笔尖货这其他工具在手写板表面时使用BTN_TOOL_<name>报告事件。使用ABS_{X,Y}来报告工具的位置事件。
当工具和手写板接触时使用BTN_TOUCH上报。BTN_{STYLUS,STYLUS2}用于上报工具本身的按钮消息。
除了BTN_{MOUSE,LEFT},其他任何按钮都可以使用。通常用BTN_{0,1,2,etc.}来表示未标记的按钮。
不要使用有一以的按键,想BTN_FORWARD,除非按键在设备上特殊标记了。

抱歉!评论已关闭.