blob: 92db509541696f6462b2068d029ad43556ae7d63 [file] [log] [blame]
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -07001=================
2Input event codes
3=================
4
5
Chase Douglasb1e064b2011-04-12 23:29:07 -07006The input protocol uses a map of types and codes to express input device values
7to userspace. This document describes the types and codes and how and when they
8may be used.
9
10A single hardware event generates multiple input events. Each input event
11contains the new value of a single data item. A special event type, EV_SYN, is
12used to separate input events into packets of input data changes occurring at
13the same moment in time. In the following, the term "event" refers to a single
14input event encompassing a type, code, and value.
15
16The input protocol is a stateful protocol. Events are emitted only when values
17of event codes have changed. However, the state is maintained within the Linux
18input subsystem; drivers do not need to maintain the state and may attempt to
19emit unchanged values without harm. Userspace may obtain the current state of
20event code values using the EVIOCG* ioctls defined in linux/input.h. The event
21reports supported by a device are also provided by sysfs in
22class/input/event*/device/capabilities/, and the properties of a device are
23provided in class/input/event*/device/properties.
24
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070025Event types
Henrik Rydbergd04df022012-02-01 09:12:24 -080026===========
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070027
Henrik Rydbergd04df022012-02-01 09:12:24 -080028Event types are groupings of codes under a logical input construct. Each
29type has a set of applicable codes to be used in generating events. See the
30Codes section for details on valid codes for each type.
Chase Douglasb1e064b2011-04-12 23:29:07 -070031
32* EV_SYN:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070033
Chase Douglasb1e064b2011-04-12 23:29:07 -070034 - Used as markers to separate events. Events may be separated in time or in
35 space, such as with the multitouch protocol.
36
37* EV_KEY:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070038
Chase Douglasb1e064b2011-04-12 23:29:07 -070039 - Used to describe state changes of keyboards, buttons, or other key-like
40 devices.
41
42* EV_REL:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070043
Chase Douglasb1e064b2011-04-12 23:29:07 -070044 - Used to describe relative axis value changes, e.g. moving the mouse 5 units
45 to the left.
46
47* EV_ABS:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070048
Chase Douglasb1e064b2011-04-12 23:29:07 -070049 - Used to describe absolute axis value changes, e.g. describing the
50 coordinates of a touch on a touchscreen.
51
52* EV_MSC:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070053
Chase Douglasb1e064b2011-04-12 23:29:07 -070054 - Used to describe miscellaneous input data that do not fit into other types.
55
56* EV_SW:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070057
Chase Douglasb1e064b2011-04-12 23:29:07 -070058 - Used to describe binary state input switches.
59
60* EV_LED:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070061
Chase Douglasb1e064b2011-04-12 23:29:07 -070062 - Used to turn LEDs on devices on and off.
63
64* EV_SND:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070065
Chase Douglasb1e064b2011-04-12 23:29:07 -070066 - Used to output sound to devices.
67
68* EV_REP:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070069
Chase Douglasb1e064b2011-04-12 23:29:07 -070070 - Used for autorepeating devices.
71
72* EV_FF:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070073
Chase Douglasb1e064b2011-04-12 23:29:07 -070074 - Used to send force feedback commands to an input device.
75
76* EV_PWR:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070077
Chase Douglasb1e064b2011-04-12 23:29:07 -070078 - A special type for power button and switch input.
79
80* EV_FF_STATUS:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070081
Chase Douglasb1e064b2011-04-12 23:29:07 -070082 - Used to receive force feedback device status.
83
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070084Event codes
Henrik Rydbergd04df022012-02-01 09:12:24 -080085===========
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070086
Henrik Rydbergd04df022012-02-01 09:12:24 -080087Event codes define the precise type of event.
Chase Douglasb1e064b2011-04-12 23:29:07 -070088
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070089EV_SYN
90------
91
Chase Douglasb1e064b2011-04-12 23:29:07 -070092EV_SYN event values are undefined. Their usage is defined only by when they are
93sent in the evdev event stream.
94
95* SYN_REPORT:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -070096
Chase Douglasb1e064b2011-04-12 23:29:07 -070097 - Used to synchronize and separate events into packets of input data changes
98 occurring at the same moment in time. For example, motion of a mouse may set
99 the REL_X and REL_Y values for one motion, then emit a SYN_REPORT. The next
100 motion will emit more REL_X and REL_Y values and send another SYN_REPORT.
101
102* SYN_CONFIG:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700103
Chase Douglasb1e064b2011-04-12 23:29:07 -0700104 - TBD
105
106* SYN_MT_REPORT:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700107
Chase Douglasb1e064b2011-04-12 23:29:07 -0700108 - Used to synchronize and separate touch events. See the
109 multi-touch-protocol.txt document for more information.
110
Jeff Brown9fb0f142011-04-12 23:29:38 -0700111* SYN_DROPPED:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700112
Jeff Brown9fb0f142011-04-12 23:29:38 -0700113 - Used to indicate buffer overrun in the evdev client's event queue.
114 Client should ignore all events up to and including next SYN_REPORT
115 event and query the device (using EVIOCG* ioctls) to obtain its
116 current state.
117
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700118EV_KEY
119------
120
Chase Douglasb1e064b2011-04-12 23:29:07 -0700121EV_KEY events take the form KEY_<name> or BTN_<name>. For example, KEY_A is used
122to represent the 'A' key on a keyboard. When a key is depressed, an event with
123the key's code is emitted with value 1. When the key is released, an event is
124emitted with value 0. Some hardware send events when a key is repeated. These
125events have a value of 2. In general, KEY_<name> is used for keyboard keys, and
126BTN_<name> is used for other types of momentary switch events.
127
128A few EV_KEY codes have special meanings:
129
130* BTN_TOOL_<name>:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700131
Chase Douglasb1e064b2011-04-12 23:29:07 -0700132 - These codes are used in conjunction with input trackpads, tablets, and
133 touchscreens. These devices may be used with fingers, pens, or other tools.
134 When an event occurs and a tool is used, the corresponding BTN_TOOL_<name>
135 code should be set to a value of 1. When the tool is no longer interacting
136 with the input device, the BTN_TOOL_<name> code should be reset to 0. All
137 trackpads, tablets, and touchscreens should use at least one BTN_TOOL_<name>
138 code when events are generated.
139
140* BTN_TOUCH:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700141
Chase Douglasb1e064b2011-04-12 23:29:07 -0700142 BTN_TOUCH is used for touch contact. While an input tool is determined to be
143 within meaningful physical contact, the value of this property must be set
144 to 1. Meaningful physical contact may mean any contact, or it may mean
145 contact conditioned by an implementation defined property. For example, a
146 touchpad may set the value to 1 only when the touch pressure rises above a
147 certain value. BTN_TOUCH may be combined with BTN_TOOL_<name> codes. For
148 example, a pen tablet may set BTN_TOOL_PEN to 1 and BTN_TOUCH to 0 while the
149 pen is hovering over but not touching the tablet surface.
150
151Note: For appropriate function of the legacy mousedev emulation driver,
152BTN_TOUCH must be the first evdev code emitted in a synchronization frame.
153
154Note: Historically a touch device with BTN_TOOL_FINGER and BTN_TOUCH was
155interpreted as a touchpad by userspace, while a similar device without
156BTN_TOOL_FINGER was interpreted as a touchscreen. For backwards compatibility
157with current userspace it is recommended to follow this distinction. In the
158future, this distinction will be deprecated and the device properties ioctl
159EVIOCGPROP, defined in linux/input.h, will be used to convey the device type.
160
161* BTN_TOOL_FINGER, BTN_TOOL_DOUBLETAP, BTN_TOOL_TRIPLETAP, BTN_TOOL_QUADTAP:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700162
Chase Douglasb1e064b2011-04-12 23:29:07 -0700163 - These codes denote one, two, three, and four finger interaction on a
164 trackpad or touchscreen. For example, if the user uses two fingers and moves
165 them on the touchpad in an effort to scroll content on screen,
166 BTN_TOOL_DOUBLETAP should be set to value 1 for the duration of the motion.
167 Note that all BTN_TOOL_<name> codes and the BTN_TOUCH code are orthogonal in
168 purpose. A trackpad event generated by finger touches should generate events
169 for one code from each group. At most only one of these BTN_TOOL_<name>
170 codes should have a value of 1 during any synchronization frame.
171
172Note: Historically some drivers emitted multiple of the finger count codes with
173a value of 1 in the same synchronization frame. This usage is deprecated.
174
175Note: In multitouch drivers, the input_mt_report_finger_count() function should
176be used to emit these codes. Please see multi-touch-protocol.txt for details.
177
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700178EV_REL
179------
180
Chase Douglasb1e064b2011-04-12 23:29:07 -0700181EV_REL events describe relative changes in a property. For example, a mouse may
182move to the left by a certain number of units, but its absolute position in
183space is unknown. If the absolute position is known, EV_ABS codes should be used
184instead of EV_REL codes.
185
186A few EV_REL codes have special meanings:
187
188* REL_WHEEL, REL_HWHEEL:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700189
Chase Douglasb1e064b2011-04-12 23:29:07 -0700190 - These codes are used for vertical and horizontal scroll wheels,
191 respectively.
192
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700193EV_ABS
194------
195
Chase Douglasb1e064b2011-04-12 23:29:07 -0700196EV_ABS events describe absolute changes in a property. For example, a touchpad
197may emit coordinates for a touch location.
198
199A few EV_ABS codes have special meanings:
200
201* ABS_DISTANCE:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700202
Chase Douglasb1e064b2011-04-12 23:29:07 -0700203 - Used to describe the distance of a tool from an interaction surface. This
204 event should only be emitted while the tool is hovering, meaning in close
205 proximity of the device and while the value of the BTN_TOUCH code is 0. If
206 the input device may be used freely in three dimensions, consider ABS_Z
207 instead.
Peter Hutterer7eb5ca02016-04-06 10:14:46 -0700208 - BTN_TOOL_<name> should be set to 1 when the tool comes into detectable
209 proximity and set to 0 when the tool leaves detectable proximity.
210 BTN_TOOL_<name> signals the type of tool that is currently detected by the
211 hardware and is otherwise independent of ABS_DISTANCE and/or BTN_TOUCH.
Chase Douglasb1e064b2011-04-12 23:29:07 -0700212
213* ABS_MT_<name>:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700214
Chase Douglasb1e064b2011-04-12 23:29:07 -0700215 - Used to describe multitouch input events. Please see
216 multi-touch-protocol.txt for details.
217
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700218EV_SW
219-----
220
Chase Douglasb1e064b2011-04-12 23:29:07 -0700221EV_SW events describe stateful binary switches. For example, the SW_LID code is
222used to denote when a laptop lid is closed.
223
224Upon binding to a device or resuming from suspend, a driver must report
225the current switch state. This ensures that the device, kernel, and userspace
226state is in sync.
227
228Upon resume, if the switch state is the same as before suspend, then the input
229subsystem will filter out the duplicate switch state reports. The driver does
230not need to keep the state of the switch at any time.
231
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700232EV_MSC
233------
234
Chase Douglasb1e064b2011-04-12 23:29:07 -0700235EV_MSC events are used for input and output events that do not fall under other
236categories.
237
Benjamin Tissoiresaf8036d2012-11-14 16:59:21 +0100238A few EV_MSC codes have special meaning:
239
240* MSC_TIMESTAMP:
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700241
Benjamin Tissoiresaf8036d2012-11-14 16:59:21 +0100242 - Used to report the number of microseconds since the last reset. This event
243 should be coded as an uint32 value, which is allowed to wrap around with
244 no special consequence. It is assumed that the time difference between two
245 consecutive events is reliable on a reasonable time scale (hours).
246 A reset to zero can happen, in which case the time since the last event is
247 unknown. If the device does not provide this information, the driver must
248 not provide it to user space.
249
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700250EV_LED
251------
252
Chase Douglasb1e064b2011-04-12 23:29:07 -0700253EV_LED events are used for input and output to set and query the state of
254various LEDs on devices.
255
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700256EV_REP
257------
258
Chase Douglasb1e064b2011-04-12 23:29:07 -0700259EV_REP events are used for specifying autorepeating events.
260
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700261EV_SND
262------
263
Chase Douglasb1e064b2011-04-12 23:29:07 -0700264EV_SND events are used for sending sound commands to simple sound output
265devices.
266
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700267EV_FF
268-----
269
Chase Douglasb1e064b2011-04-12 23:29:07 -0700270EV_FF events are used to initialize a force feedback capable device and to cause
271such device to feedback.
272
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700273EV_PWR
274------
275
Chase Douglasb1e064b2011-04-12 23:29:07 -0700276EV_PWR events are a special type of event used specifically for power
Masanari Iidaad4a6eb2015-02-25 20:30:22 +0900277management. Its usage is not well defined. To be addressed later.
Chase Douglasb1e064b2011-04-12 23:29:07 -0700278
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700279Device properties
Henrik Rydbergd04df022012-02-01 09:12:24 -0800280=================
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700281
Henrik Rydbergd04df022012-02-01 09:12:24 -0800282Normally, userspace sets up an input device based on the data it emits,
283i.e., the event types. In the case of two devices emitting the same event
284types, additional information can be provided in the form of device
285properties.
286
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700287INPUT_PROP_DIRECT + INPUT_PROP_POINTER
Henrik Rydbergd04df022012-02-01 09:12:24 -0800288--------------------------------------
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700289
Henrik Rydbergd04df022012-02-01 09:12:24 -0800290The INPUT_PROP_DIRECT property indicates that device coordinates should be
291directly mapped to screen coordinates (not taking into account trivial
292transformations, such as scaling, flipping and rotating). Non-direct input
293devices require non-trivial transformation, such as absolute to relative
294transformation for touchpads. Typical direct input devices: touchscreens,
295drawing tablets; non-direct devices: touchpads, mice.
296
297The INPUT_PROP_POINTER property indicates that the device is not transposed
298on the screen and thus requires use of an on-screen pointer to trace user's
299movements. Typical pointer devices: touchpads, tablets, mice; non-pointer
300device: touchscreen.
301
302If neither INPUT_PROP_DIRECT or INPUT_PROP_POINTER are set, the property is
303considered undefined and the device type should be deduced in the
304traditional way, using emitted event types.
305
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700306INPUT_PROP_BUTTONPAD
Henrik Rydbergd04df022012-02-01 09:12:24 -0800307--------------------
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700308
Henrik Rydbergd04df022012-02-01 09:12:24 -0800309For touchpads where the button is placed beneath the surface, such that
310pressing down on the pad causes a button click, this property should be
311set. Common in clickpad notebooks and macbooks from 2009 and onwards.
312
313Originally, the buttonpad property was coded into the bcm5974 driver
314version field under the name integrated button. For backwards
315compatibility, both methods need to be checked in userspace.
316
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700317INPUT_PROP_SEMI_MT
Henrik Rydbergd04df022012-02-01 09:12:24 -0800318------------------
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700319
Henrik Rydbergd04df022012-02-01 09:12:24 -0800320Some touchpads, most common between 2008 and 2011, can detect the presence
321of multiple contacts without resolving the individual positions; only the
322number of contacts and a rectangular shape is known. For such
323touchpads, the semi-mt property should be set.
324
325Depending on the device, the rectangle may enclose all touches, like a
326bounding box, or just some of them, for instance the two most recent
327touches. The diversity makes the rectangle of limited use, but some
328gestures can normally be extracted from it.
329
330If INPUT_PROP_SEMI_MT is not set, the device is assumed to be a true MT
331device.
332
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700333INPUT_PROP_TOPBUTTONPAD
Peter Huttererf62d14a2014-07-21 17:51:35 -0700334-----------------------
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700335
336Some laptops, most notably the Lenovo 40 series provide a trackstick
Peter Huttererf62d14a2014-07-21 17:51:35 -0700337device but do not have physical buttons associated with the trackstick
338device. Instead, the top area of the touchpad is marked to show
339visual/haptic areas for left, middle, right buttons intended to be used
340with the trackstick.
341
342If INPUT_PROP_TOPBUTTONPAD is set, userspace should emulate buttons
343accordingly. This property does not affect kernel behavior.
344The kernel does not provide button emulation for such devices but treats
345them as any other INPUT_PROP_BUTTONPAD device.
346
Peter Hutterer33096772015-03-27 09:59:55 -0700347INPUT_PROP_ACCELEROMETER
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700348------------------------
349
Peter Hutterer33096772015-03-27 09:59:55 -0700350Directional axes on this device (absolute and/or relative x, y, z) represent
351accelerometer data. All other axes retain their meaning. A device must not mix
352regular directional axes and accelerometer axes on the same event node.
353
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700354Guidelines
Chase Douglasb1e064b2011-04-12 23:29:07 -0700355==========
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700356
Chase Douglasb1e064b2011-04-12 23:29:07 -0700357The guidelines below ensure proper single-touch and multi-finger functionality.
358For multi-touch functionality, see the multi-touch-protocol.txt document for
359more information.
360
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700361Mice
362----
363
Chase Douglasb1e064b2011-04-12 23:29:07 -0700364REL_{X,Y} must be reported when the mouse moves. BTN_LEFT must be used to report
365the primary button press. BTN_{MIDDLE,RIGHT,4,5,etc.} should be used to report
366further buttons of the device. REL_WHEEL and REL_HWHEEL should be used to report
367scroll wheel events where available.
368
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700369Touchscreens
370------------
371
Chase Douglasb1e064b2011-04-12 23:29:07 -0700372ABS_{X,Y} must be reported with the location of the touch. BTN_TOUCH must be
373used to report when a touch is active on the screen.
374BTN_{MOUSE,LEFT,MIDDLE,RIGHT} must not be reported as the result of touch
375contact. BTN_TOOL_<name> events should be reported where possible.
376
Henrik Rydbergd04df022012-02-01 09:12:24 -0800377For new hardware, INPUT_PROP_DIRECT should be set.
378
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700379Trackpads
380---------
381
Chase Douglasb1e064b2011-04-12 23:29:07 -0700382Legacy trackpads that only provide relative position information must report
383events like mice described above.
384
385Trackpads that provide absolute touch position must report ABS_{X,Y} for the
386location of the touch. BTN_TOUCH should be used to report when a touch is active
387on the trackpad. Where multi-finger support is available, BTN_TOOL_<name> should
388be used to report the number of touches active on the trackpad.
389
Henrik Rydbergd04df022012-02-01 09:12:24 -0800390For new hardware, INPUT_PROP_POINTER should be set.
391
Mauro Carvalho Chehabacbdca82017-04-04 17:39:30 -0700392Tablets
393-------
394
Chase Douglasb1e064b2011-04-12 23:29:07 -0700395BTN_TOOL_<name> events must be reported when a stylus or other tool is active on
396the tablet. ABS_{X,Y} must be reported with the location of the tool. BTN_TOUCH
397should be used to report when the tool is in contact with the tablet.
398BTN_{STYLUS,STYLUS2} should be used to report buttons on the tool itself. Any
399button may be used for buttons on the tablet except BTN_{MOUSE,LEFT}.
400BTN_{0,1,2,etc} are good generic codes for unlabeled buttons. Do not use
401meaningful buttons, like BTN_FORWARD, unless the button is labeled for that
402purpose on the device.
Henrik Rydbergd04df022012-02-01 09:12:24 -0800403
404For new hardware, both INPUT_PROP_DIRECT and INPUT_PROP_POINTER should be set.