0001 .. _input-event-codes:
0002
0003 =================
0004 Input event codes
0005 =================
0006
0007
0008 The input protocol uses a map of types and codes to express input device values
0009 to userspace. This document describes the types and codes and how and when they
0010 may be used.
0011
0012 A single hardware event generates multiple input events. Each input event
0013 contains the new value of a single data item. A special event type, EV_SYN, is
0014 used to separate input events into packets of input data changes occurring at
0015 the same moment in time. In the following, the term "event" refers to a single
0016 input event encompassing a type, code, and value.
0017
0018 The input protocol is a stateful protocol. Events are emitted only when values
0019 of event codes have changed. However, the state is maintained within the Linux
0020 input subsystem; drivers do not need to maintain the state and may attempt to
0021 emit unchanged values without harm. Userspace may obtain the current state of
0022 event code values using the EVIOCG* ioctls defined in linux/input.h. The event
0023 reports supported by a device are also provided by sysfs in
0024 class/input/event*/device/capabilities/, and the properties of a device are
0025 provided in class/input/event*/device/properties.
0026
0027 Event types
0028 ===========
0029
0030 Event types are groupings of codes under a logical input construct. Each
0031 type has a set of applicable codes to be used in generating events. See the
0032 Codes section for details on valid codes for each type.
0033
0034 * EV_SYN:
0035
0036 - Used as markers to separate events. Events may be separated in time or in
0037 space, such as with the multitouch protocol.
0038
0039 * EV_KEY:
0040
0041 - Used to describe state changes of keyboards, buttons, or other key-like
0042 devices.
0043
0044 * EV_REL:
0045
0046 - Used to describe relative axis value changes, e.g. moving the mouse 5 units
0047 to the left.
0048
0049 * EV_ABS:
0050
0051 - Used to describe absolute axis value changes, e.g. describing the
0052 coordinates of a touch on a touchscreen.
0053
0054 * EV_MSC:
0055
0056 - Used to describe miscellaneous input data that do not fit into other types.
0057
0058 * EV_SW:
0059
0060 - Used to describe binary state input switches.
0061
0062 * EV_LED:
0063
0064 - Used to turn LEDs on devices on and off.
0065
0066 * EV_SND:
0067
0068 - Used to output sound to devices.
0069
0070 * EV_REP:
0071
0072 - Used for autorepeating devices.
0073
0074 * EV_FF:
0075
0076 - Used to send force feedback commands to an input device.
0077
0078 * EV_PWR:
0079
0080 - A special type for power button and switch input.
0081
0082 * EV_FF_STATUS:
0083
0084 - Used to receive force feedback device status.
0085
0086 Event codes
0087 ===========
0088
0089 Event codes define the precise type of event.
0090
0091 EV_SYN
0092 ------
0093
0094 EV_SYN event values are undefined. Their usage is defined only by when they are
0095 sent in the evdev event stream.
0096
0097 * SYN_REPORT:
0098
0099 - Used to synchronize and separate events into packets of input data changes
0100 occurring at the same moment in time. For example, motion of a mouse may set
0101 the REL_X and REL_Y values for one motion, then emit a SYN_REPORT. The next
0102 motion will emit more REL_X and REL_Y values and send another SYN_REPORT.
0103
0104 * SYN_CONFIG:
0105
0106 - TBD
0107
0108 * SYN_MT_REPORT:
0109
0110 - Used to synchronize and separate touch events. See the
0111 multi-touch-protocol.txt document for more information.
0112
0113 * SYN_DROPPED:
0114
0115 - Used to indicate buffer overrun in the evdev client's event queue.
0116 Client should ignore all events up to and including next SYN_REPORT
0117 event and query the device (using EVIOCG* ioctls) to obtain its
0118 current state.
0119
0120 EV_KEY
0121 ------
0122
0123 EV_KEY events take the form KEY_<name> or BTN_<name>. For example, KEY_A is used
0124 to represent the 'A' key on a keyboard. When a key is depressed, an event with
0125 the key's code is emitted with value 1. When the key is released, an event is
0126 emitted with value 0. Some hardware send events when a key is repeated. These
0127 events have a value of 2. In general, KEY_<name> is used for keyboard keys, and
0128 BTN_<name> is used for other types of momentary switch events.
0129
0130 A few EV_KEY codes have special meanings:
0131
0132 * BTN_TOOL_<name>:
0133
0134 - These codes are used in conjunction with input trackpads, tablets, and
0135 touchscreens. These devices may be used with fingers, pens, or other tools.
0136 When an event occurs and a tool is used, the corresponding BTN_TOOL_<name>
0137 code should be set to a value of 1. When the tool is no longer interacting
0138 with the input device, the BTN_TOOL_<name> code should be reset to 0. All
0139 trackpads, tablets, and touchscreens should use at least one BTN_TOOL_<name>
0140 code when events are generated. Likewise all trackpads, tablets, and
0141 touchscreens should export only one BTN_TOOL_<name> at a time. To not break
0142 existing userspace, it is recommended to not switch tool in one EV_SYN frame
0143 but first emitting the old BTN_TOOL_<name> at 0, then emit one SYN_REPORT
0144 and then set the new BTN_TOOL_<name> at 1.
0145
0146 * BTN_TOUCH:
0147
0148 BTN_TOUCH is used for touch contact. While an input tool is determined to be
0149 within meaningful physical contact, the value of this property must be set
0150 to 1. Meaningful physical contact may mean any contact, or it may mean
0151 contact conditioned by an implementation defined property. For example, a
0152 touchpad may set the value to 1 only when the touch pressure rises above a
0153 certain value. BTN_TOUCH may be combined with BTN_TOOL_<name> codes. For
0154 example, a pen tablet may set BTN_TOOL_PEN to 1 and BTN_TOUCH to 0 while the
0155 pen is hovering over but not touching the tablet surface.
0156
0157 Note: For appropriate function of the legacy mousedev emulation driver,
0158 BTN_TOUCH must be the first evdev code emitted in a synchronization frame.
0159
0160 Note: Historically a touch device with BTN_TOOL_FINGER and BTN_TOUCH was
0161 interpreted as a touchpad by userspace, while a similar device without
0162 BTN_TOOL_FINGER was interpreted as a touchscreen. For backwards compatibility
0163 with current userspace it is recommended to follow this distinction. In the
0164 future, this distinction will be deprecated and the device properties ioctl
0165 EVIOCGPROP, defined in linux/input.h, will be used to convey the device type.
0166
0167 * BTN_TOOL_FINGER, BTN_TOOL_DOUBLETAP, BTN_TOOL_TRIPLETAP, BTN_TOOL_QUADTAP:
0168
0169 - These codes denote one, two, three, and four finger interaction on a
0170 trackpad or touchscreen. For example, if the user uses two fingers and moves
0171 them on the touchpad in an effort to scroll content on screen,
0172 BTN_TOOL_DOUBLETAP should be set to value 1 for the duration of the motion.
0173 Note that all BTN_TOOL_<name> codes and the BTN_TOUCH code are orthogonal in
0174 purpose. A trackpad event generated by finger touches should generate events
0175 for one code from each group. At most only one of these BTN_TOOL_<name>
0176 codes should have a value of 1 during any synchronization frame.
0177
0178 Note: Historically some drivers emitted multiple of the finger count codes with
0179 a value of 1 in the same synchronization frame. This usage is deprecated.
0180
0181 Note: In multitouch drivers, the input_mt_report_finger_count() function should
0182 be used to emit these codes. Please see multi-touch-protocol.txt for details.
0183
0184 EV_REL
0185 ------
0186
0187 EV_REL events describe relative changes in a property. For example, a mouse may
0188 move to the left by a certain number of units, but its absolute position in
0189 space is unknown. If the absolute position is known, EV_ABS codes should be used
0190 instead of EV_REL codes.
0191
0192 A few EV_REL codes have special meanings:
0193
0194 * REL_WHEEL, REL_HWHEEL:
0195
0196 - These codes are used for vertical and horizontal scroll wheels,
0197 respectively. The value is the number of detents moved on the wheel, the
0198 physical size of which varies by device. For high-resolution wheels
0199 this may be an approximation based on the high-resolution scroll events,
0200 see REL_WHEEL_HI_RES. These event codes are legacy codes and
0201 REL_WHEEL_HI_RES and REL_HWHEEL_HI_RES should be preferred where
0202 available.
0203
0204 * REL_WHEEL_HI_RES, REL_HWHEEL_HI_RES:
0205
0206 - High-resolution scroll wheel data. The accumulated value 120 represents
0207 movement by one detent. For devices that do not provide high-resolution
0208 scrolling, the value is always a multiple of 120. For devices with
0209 high-resolution scrolling, the value may be a fraction of 120.
0210
0211 If a vertical scroll wheel supports high-resolution scrolling, this code
0212 will be emitted in addition to REL_WHEEL or REL_HWHEEL. The REL_WHEEL
0213 and REL_HWHEEL may be an approximation based on the high-resolution
0214 scroll events. There is no guarantee that the high-resolution data
0215 is a multiple of 120 at the time of an emulated REL_WHEEL or REL_HWHEEL
0216 event.
0217
0218 EV_ABS
0219 ------
0220
0221 EV_ABS events describe absolute changes in a property. For example, a touchpad
0222 may emit coordinates for a touch location.
0223
0224 A few EV_ABS codes have special meanings:
0225
0226 * ABS_DISTANCE:
0227
0228 - Used to describe the distance of a tool from an interaction surface. This
0229 event should only be emitted while the tool is hovering, meaning in close
0230 proximity of the device and while the value of the BTN_TOUCH code is 0. If
0231 the input device may be used freely in three dimensions, consider ABS_Z
0232 instead.
0233 - BTN_TOOL_<name> should be set to 1 when the tool comes into detectable
0234 proximity and set to 0 when the tool leaves detectable proximity.
0235 BTN_TOOL_<name> signals the type of tool that is currently detected by the
0236 hardware and is otherwise independent of ABS_DISTANCE and/or BTN_TOUCH.
0237
0238 * ABS_MT_<name>:
0239
0240 - Used to describe multitouch input events. Please see
0241 multi-touch-protocol.txt for details.
0242
0243 * ABS_PRESSURE/ABS_MT_PRESSURE:
0244
0245 - For touch devices, many devices converted contact size into pressure.
0246 A finger flattens with pressure, causing a larger contact area and thus
0247 pressure and contact size are directly related. This is not the case
0248 for other devices, for example digitizers and touchpads with a true
0249 pressure sensor ("pressure pads").
0250
0251 A device should set the resolution of the axis to indicate whether the
0252 pressure is in measurable units. If the resolution is zero, the
0253 pressure data is in arbitrary units. If the resolution is non-zero, the
0254 pressure data is in units/gram. For example, a value of 10 with a
0255 resolution of 1 represents 10 gram, a value of 10 with a resolution of
0256 1000 represents 10 microgram.
0257
0258 EV_SW
0259 -----
0260
0261 EV_SW events describe stateful binary switches. For example, the SW_LID code is
0262 used to denote when a laptop lid is closed.
0263
0264 Upon binding to a device or resuming from suspend, a driver must report
0265 the current switch state. This ensures that the device, kernel, and userspace
0266 state is in sync.
0267
0268 Upon resume, if the switch state is the same as before suspend, then the input
0269 subsystem will filter out the duplicate switch state reports. The driver does
0270 not need to keep the state of the switch at any time.
0271
0272 EV_MSC
0273 ------
0274
0275 EV_MSC events are used for input and output events that do not fall under other
0276 categories.
0277
0278 A few EV_MSC codes have special meaning:
0279
0280 * MSC_TIMESTAMP:
0281
0282 - Used to report the number of microseconds since the last reset. This event
0283 should be coded as an uint32 value, which is allowed to wrap around with
0284 no special consequence. It is assumed that the time difference between two
0285 consecutive events is reliable on a reasonable time scale (hours).
0286 A reset to zero can happen, in which case the time since the last event is
0287 unknown. If the device does not provide this information, the driver must
0288 not provide it to user space.
0289
0290 EV_LED
0291 ------
0292
0293 EV_LED events are used for input and output to set and query the state of
0294 various LEDs on devices.
0295
0296 EV_REP
0297 ------
0298
0299 EV_REP events are used for specifying autorepeating events.
0300
0301 EV_SND
0302 ------
0303
0304 EV_SND events are used for sending sound commands to simple sound output
0305 devices.
0306
0307 EV_FF
0308 -----
0309
0310 EV_FF events are used to initialize a force feedback capable device and to cause
0311 such device to feedback.
0312
0313 EV_PWR
0314 ------
0315
0316 EV_PWR events are a special type of event used specifically for power
0317 management. Its usage is not well defined. To be addressed later.
0318
0319 Device properties
0320 =================
0321
0322 Normally, userspace sets up an input device based on the data it emits,
0323 i.e., the event types. In the case of two devices emitting the same event
0324 types, additional information can be provided in the form of device
0325 properties.
0326
0327 INPUT_PROP_DIRECT + INPUT_PROP_POINTER
0328 --------------------------------------
0329
0330 The INPUT_PROP_DIRECT property indicates that device coordinates should be
0331 directly mapped to screen coordinates (not taking into account trivial
0332 transformations, such as scaling, flipping and rotating). Non-direct input
0333 devices require non-trivial transformation, such as absolute to relative
0334 transformation for touchpads. Typical direct input devices: touchscreens,
0335 drawing tablets; non-direct devices: touchpads, mice.
0336
0337 The INPUT_PROP_POINTER property indicates that the device is not transposed
0338 on the screen and thus requires use of an on-screen pointer to trace user's
0339 movements. Typical pointer devices: touchpads, tablets, mice; non-pointer
0340 device: touchscreen.
0341
0342 If neither INPUT_PROP_DIRECT or INPUT_PROP_POINTER are set, the property is
0343 considered undefined and the device type should be deduced in the
0344 traditional way, using emitted event types.
0345
0346 INPUT_PROP_BUTTONPAD
0347 --------------------
0348
0349 For touchpads where the button is placed beneath the surface, such that
0350 pressing down on the pad causes a button click, this property should be
0351 set. Common in Clickpad notebooks and Macbooks from 2009 and onwards.
0352
0353 Originally, the buttonpad property was coded into the bcm5974 driver
0354 version field under the name integrated button. For backwards
0355 compatibility, both methods need to be checked in userspace.
0356
0357 INPUT_PROP_SEMI_MT
0358 ------------------
0359
0360 Some touchpads, most common between 2008 and 2011, can detect the presence
0361 of multiple contacts without resolving the individual positions; only the
0362 number of contacts and a rectangular shape is known. For such
0363 touchpads, the SEMI_MT property should be set.
0364
0365 Depending on the device, the rectangle may enclose all touches, like a
0366 bounding box, or just some of them, for instance the two most recent
0367 touches. The diversity makes the rectangle of limited use, but some
0368 gestures can normally be extracted from it.
0369
0370 If INPUT_PROP_SEMI_MT is not set, the device is assumed to be a true MT
0371 device.
0372
0373 INPUT_PROP_TOPBUTTONPAD
0374 -----------------------
0375
0376 Some laptops, most notably the Lenovo 40 series provide a trackstick
0377 device but do not have physical buttons associated with the trackstick
0378 device. Instead, the top area of the touchpad is marked to show
0379 visual/haptic areas for left, middle, right buttons intended to be used
0380 with the trackstick.
0381
0382 If INPUT_PROP_TOPBUTTONPAD is set, userspace should emulate buttons
0383 accordingly. This property does not affect kernel behavior.
0384 The kernel does not provide button emulation for such devices but treats
0385 them as any other INPUT_PROP_BUTTONPAD device.
0386
0387 INPUT_PROP_ACCELEROMETER
0388 ------------------------
0389
0390 Directional axes on this device (absolute and/or relative x, y, z) represent
0391 accelerometer data. Some devices also report gyroscope data, which devices
0392 can report through the rotational axes (absolute and/or relative rx, ry, rz).
0393
0394 All other axes retain their meaning. A device must not mix
0395 regular directional axes and accelerometer axes on the same event node.
0396
0397 Guidelines
0398 ==========
0399
0400 The guidelines below ensure proper single-touch and multi-finger functionality.
0401 For multi-touch functionality, see the multi-touch-protocol.rst document for
0402 more information.
0403
0404 Mice
0405 ----
0406
0407 REL_{X,Y} must be reported when the mouse moves. BTN_LEFT must be used to report
0408 the primary button press. BTN_{MIDDLE,RIGHT,4,5,etc.} should be used to report
0409 further buttons of the device. REL_WHEEL and REL_HWHEEL should be used to report
0410 scroll wheel events where available.
0411
0412 Touchscreens
0413 ------------
0414
0415 ABS_{X,Y} must be reported with the location of the touch. BTN_TOUCH must be
0416 used to report when a touch is active on the screen.
0417 BTN_{MOUSE,LEFT,MIDDLE,RIGHT} must not be reported as the result of touch
0418 contact. BTN_TOOL_<name> events should be reported where possible.
0419
0420 For new hardware, INPUT_PROP_DIRECT should be set.
0421
0422 Trackpads
0423 ---------
0424
0425 Legacy trackpads that only provide relative position information must report
0426 events like mice described above.
0427
0428 Trackpads that provide absolute touch position must report ABS_{X,Y} for the
0429 location of the touch. BTN_TOUCH should be used to report when a touch is active
0430 on the trackpad. Where multi-finger support is available, BTN_TOOL_<name> should
0431 be used to report the number of touches active on the trackpad.
0432
0433 For new hardware, INPUT_PROP_POINTER should be set.
0434
0435 Tablets
0436 -------
0437
0438 BTN_TOOL_<name> events must be reported when a stylus or other tool is active on
0439 the tablet. ABS_{X,Y} must be reported with the location of the tool. BTN_TOUCH
0440 should be used to report when the tool is in contact with the tablet.
0441 BTN_{STYLUS,STYLUS2} should be used to report buttons on the tool itself. Any
0442 button may be used for buttons on the tablet except BTN_{MOUSE,LEFT}.
0443 BTN_{0,1,2,etc} are good generic codes for unlabeled buttons. Do not use
0444 meaningful buttons, like BTN_FORWARD, unless the button is labeled for that
0445 purpose on the device.
0446
0447 For new hardware, both INPUT_PROP_DIRECT and INPUT_PROP_POINTER should be set.