blob: 193cbf3cb3379eb23aa8882b926645c97ecae0ac [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _ANDROID_INPUT_H
18#define _ANDROID_INPUT_H
19
20/******************************************************************
21 *
22 * IMPORTANT NOTICE:
23 *
24 * This file is part of Android's set of stable system headers
25 * exposed by the Android NDK (Native Development Kit).
26 *
27 * Third-party source AND binary code relies on the definitions
28 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
29 *
30 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
31 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
32 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
33 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
34 */
35
36/*
37 * Structures and functions to receive and process input events in
38 * native code.
39 *
40 * NOTE: These functions MUST be implemented by /system/lib/libui.so
41 */
42
43#include <sys/types.h>
44#include <android/keycodes.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/*
51 * Input device classes.
52 */
53enum {
54 /* The input device is a keyboard. */
55 INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001,
56
57 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
58 INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002,
59
60 /* The input device is a touchscreen (either single-touch or multi-touch). */
61 INPUT_DEVICE_CLASS_TOUCHSCREEN = 0x00000004,
62
63 /* The input device is a trackball. */
64 INPUT_DEVICE_CLASS_TRACKBALL = 0x00000008,
65
66 /* The input device is a multi-touch touchscreen. */
67 INPUT_DEVICE_CLASS_TOUCHSCREEN_MT= 0x00000010,
68
69 /* The input device is a directional pad. */
70 INPUT_DEVICE_CLASS_DPAD = 0x00000020
71};
72
73/*
74 * Key states (may be returned by queries about the current state of a
75 * particular key code, scan code or switch).
76 *
77 * XXX should we call this BUTTON_STATE_XXX?
78 */
79enum {
80 /* The key state is unknown or the requested key itself is not supported. */
81 KEY_STATE_UNKNOWN = -1,
82
83 /* The key is up. */
84 KEY_STATE_UP = 0,
85
86 /* The key is down. */
87 KEY_STATE_DOWN = 1,
88
89 /* The key is down but is a virtual key press that is being emulated by the system. */
90 KEY_STATE_VIRTUAL = 2
91};
92
93/*
94 * Meta key / modifer state.
95 */
96enum {
97 /* No meta keys are pressed. */
98 META_NONE = 0,
99
100 /* This mask is used to check whether one of the ALT meta keys is pressed. */
101 META_ALT_ON = 0x02,
102
103 /* This mask is used to check whether the left ALT meta key is pressed. */
104 META_ALT_LEFT_ON = 0x10,
105
106 /* This mask is used to check whether the right ALT meta key is pressed. */
107 META_ALT_RIGHT_ON = 0x20,
108
109 /* This mask is used to check whether one of the SHIFT meta keys is pressed. */
110 META_SHIFT_ON = 0x01,
111
112 /* This mask is used to check whether the left SHIFT meta key is pressed. */
113 META_SHIFT_LEFT_ON = 0x40,
114
115 /* This mask is used to check whether the right SHIFT meta key is pressed. */
116 META_SHIFT_RIGHT_ON = 0x80,
117
118 /* This mask is used to check whether the SYM meta key is pressed. */
119 META_SYM_ON = 0x04
120};
121
122/*
123 * Input events.
124 *
125 * Input events are opaque structures. Use the provided accessors functions to
126 * read their properties.
127 */
128struct input_event_t;
129typedef struct input_event_t input_event_t;
130
131/*
132 * Input event types.
133 */
134enum {
135 /* Indicates that the input event is a key event. */
136 INPUT_EVENT_TYPE_KEY = 1,
137
138 /* Indicates that the input event is a motion event. */
139 INPUT_EVENT_TYPE_MOTION = 2
140};
141
142/*
143 * Key event actions.
144 */
145enum {
146 /* The key has been pressed down. */
147 KEY_EVENT_ACTION_DOWN = 0,
148
149 /* The key has been released. */
150 KEY_EVENT_ACTION_UP = 1,
151
152 /* Multiple duplicate key events have occurred in a row, or a complex string is
153 * being delivered. The repeat_count property of the key event contains the number
154 * of times the given key code should be executed.
155 */
156 KEY_EVENT_ACTION_MULTIPLE = 2
157};
158
159/*
160 * Key event flags.
161 */
162enum {
163 /* This mask is set if the device woke because of this key event. */
164 KEY_EVENT_FLAG_WOKE_HERE = 0x1,
165
166 /* This mask is set if the key event was generated by a software keyboard. */
167 KEY_EVENT_FLAG_SOFT_KEYBOARD = 0x2,
168
169 /* This mask is set if we don't want the key event to cause us to leave touch mode. */
170 KEY_EVENT_FLAG_KEEP_TOUCH_MODE = 0x4,
171
172 /* This mask is set if an event was known to come from a trusted part
173 * of the system. That is, the event is known to come from the user,
174 * and could not have been spoofed by a third party component. */
175 KEY_EVENT_FLAG_FROM_SYSTEM = 0x8,
176
177 /* This mask is used for compatibility, to identify enter keys that are
178 * coming from an IME whose enter key has been auto-labelled "next" or
179 * "done". This allows TextView to dispatch these as normal enter keys
180 * for old applications, but still do the appropriate action when
181 * receiving them. */
182 KEY_EVENT_FLAG_EDITOR_ACTION = 0x10,
183
184 /* When associated with up key events, this indicates that the key press
185 * has been canceled. Typically this is used with virtual touch screen
186 * keys, where the user can slide from the virtual key area on to the
187 * display: in that case, the application will receive a canceled up
188 * event and should not perform the action normally associated with the
189 * key. Note that for this to work, the application can not perform an
190 * action for a key until it receives an up or the long press timeout has
191 * expired. */
192 KEY_EVENT_FLAG_CANCELED = 0x20,
193
194 /* This key event was generated by a virtual (on-screen) hard key area.
195 * Typically this is an area of the touchscreen, outside of the regular
196 * display, dedicated to "hardware" buttons. */
197 KEY_EVENT_FLAG_VIRTUAL_HARD_KEY = 0x40,
198
199 /* This flag is set for the first key repeat that occurs after the
200 * long press timeout. */
201 KEY_EVENT_FLAG_LONG_PRESS = 0x80,
202
203 /* Set when a key event has KEY_EVENT_FLAG_CANCELED set because a long
204 * press action was executed while it was down. */
205 KEY_EVENT_FLAG_CANCELED_LONG_PRESS = 0x100,
206
207 /* Set for KEY_EVENT_ACTION_UP when this event's key code is still being
208 * tracked from its initial down. That is, somebody requested that tracking
209 * started on the key down and a long press has not caused
210 * the tracking to be canceled. */
211 KEY_EVENT_FLAG_TRACKING = 0x200
212};
213
214/*
215 * Motion event actions.
216 */
217
218/* Bit shift for the action bits holding the pointer index as
219 * defined by MOTION_EVENT_ACTION_POINTER_INDEX_MASK.
220 */
221#define MOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8
222
223enum {
224 /* Bit mask of the parts of the action code that are the action itself.
225 */
226 MOTION_EVENT_ACTION_MASK = 0xff,
227
228 /* Bits in the action code that represent a pointer index, used with
229 * MOTION_EVENT_ACTION_POINTER_DOWN and MOTION_EVENT_ACTION_POINTER_UP. Shifting
230 * down by MOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer
231 * index where the data for the pointer going up or down can be found.
232 */
233 MOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00,
234
235 /* A pressed gesture has started, the motion contains the initial starting location.
236 */
237 MOTION_EVENT_ACTION_DOWN = 0,
238
239 /* A pressed gesture has finished, the motion contains the final release location
240 * as well as any intermediate points since the last down or move event.
241 */
242 MOTION_EVENT_ACTION_UP = 1,
243
244 /* A change has happened during a press gesture (between MOTION_EVENT_ACTION_DOWN and
245 * MOTION_EVENT_ACTION_UP). The motion contains the most recent point, as well as
246 * any intermediate points since the last down or move event.
247 */
248 MOTION_EVENT_ACTION_MOVE = 2,
249
250 /* The current gesture has been aborted.
251 * You will not receive any more points in it. You should treat this as
252 * an up event, but not perform any action that you normally would.
253 */
254 MOTION_EVENT_ACTION_CANCEL = 3,
255
256 /* A movement has happened outside of the normal bounds of the UI element.
257 * This does not provide a full gesture, but only the initial location of the movement/touch.
258 */
259 MOTION_EVENT_ACTION_OUTSIDE = 4,
260
261 /* A non-primary pointer has gone down.
262 * The bits in MOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
263 */
264 MOTION_EVENT_ACTION_POINTER_DOWN = 5,
265
266 /* A non-primary pointer has gone up.
267 * The bits in MOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
268 */
269 MOTION_EVENT_ACTION_POINTER_UP = 6
270};
271
272/*
273 * Motion event edge touch flags.
274 */
275enum {
276 /* No edges intersected */
277 MOTION_EVENT_EDGE_FLAG_NONE = 0,
278
279 /* Flag indicating the motion event intersected the top edge of the screen. */
280 MOTION_EVENT_EDGE_FLAG_TOP = 0x01,
281
282 /* Flag indicating the motion event intersected the bottom edge of the screen. */
283 MOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02,
284
285 /* Flag indicating the motion event intersected the left edge of the screen. */
286 MOTION_EVENT_EDGE_FLAG_LEFT = 0x04,
287
288 /* Flag indicating the motion event intersected the right edge of the screen. */
289 MOTION_EVENT_EDGE_FLAG_RIGHT = 0x08
290};
291
292/*
293 * Specifies the logical nature of an input event.
294 * For example, the nature distinguishes between motion events that represent touches and
295 * those that represent trackball moves.
296 *
297 * XXX This concept is tentative. Another idea would be to associate events with logical
298 * controllers rather than physical devices. The interpretation of an event would
299 * be made with respect to the nature of the controller that is considered the logical
300 * source of an event. The decoupling is beneficial since multiple physical (and virtual)
301 * devices could be responsible for producing events that would be associated with
302 * various logical controllers. For example, the hard keyboard, on screen keyboard,
303 * and peripheral keyboard could be mapped onto a single logical "keyboard" controller
304 * (or treated independently, if desired).
305 */
306enum {
307 INPUT_EVENT_NATURE_KEY = 1,
308 INPUT_EVENT_NATURE_TOUCH = 2,
309 INPUT_EVENT_NATURE_TRACKBALL = 3
310};
311
312/*
313 * Input event accessors.
314 *
315 * Note that most functions can only be used on input events that are of a given type.
316 * Calling these functions on input events of other types will yield undefined behavior.
317 */
318
319/*** Accessors for all input events. ***/
320
321/* Get the input event type. */
322int32_t input_event_get_type(const input_event_t* event);
323
324/* Get the id for the device that an input event came from.
325 *
326 * Input events can be generated by multiple different input devices.
327 * Use the input device id to obtain information about the input
328 * device that was responsible for generating a particular event.
329 *
330 * An input device id of 0 indicates that the event didn't come from a physical device;
331 * other numbers are arbitrary and you shouldn't depend on the values.
332 * Use the provided input device query API to obtain information about input devices.
333 */
334int32_t input_event_get_device_id(const input_event_t* event);
335
336/* Get the input event nature. */
337int32_t input_event_get_nature(const input_event_t* event);
338
339/*** Accessors for key events only. ***/
340
341/* Get the key event action. */
342int32_t key_event_get_action(const input_event_t* key_event);
343
344/* Get the key event flags. */
345int32_t key_event_get_flags(const input_event_t* key_event);
346
347/* Get the key code of the key event.
348 * This is the physical key that was pressed, not the Unicode character. */
349int32_t key_event_get_key_code(const input_event_t* key_event);
350
351/* Get the hardware key id of this key event.
352 * These values are not reliable and vary from device to device. */
353int32_t key_event_get_scan_code(const input_event_t* key_event);
354
355/* Get the meta key state. */
356int32_t key_event_get_meta_state(const input_event_t* key_event);
357
358/* Get the repeat count of the event.
359 * For both key up an key down events, this is the number of times the key has
360 * repeated with the first down starting at 0 and counting up from there. For
361 * multiple key events, this is the number of down/up pairs that have occurred. */
362int32_t key_event_get_repeat_count(const input_event_t* key_event);
363
364/* Get the time of the most recent key down event, in the
365 * java.lang.System.nanoTime() time base. If this is a down event,
366 * this will be the same as eventTime.
367 * Note that when chording keys, this value is the down time of the most recently
368 * pressed key, which may not be the same physical key of this event. */
369int64_t key_event_get_down_time(const input_event_t* key_event);
370
371/* Get the time this event occurred, in the
372 * java.lang.System.nanoTime() time base. */
373int64_t key_event_get_event_time(const input_event_t* key_event);
374
375/*** Accessors for motion events only. ***/
376
377/* Get the combined motion event action code and pointer index. */
378int32_t motion_event_get_action(const input_event_t* motion_event);
379
380/* Get the state of any meta / modifier keys that were in effect when the
381 * event was generated. */
382int32_t motion_event_get_meta_state(const input_event_t* motion_event);
383
384/* Get a bitfield indicating which edges, if any, were touched by this motion event.
385 * For touch events, clients can use this to determine if the user's finger was
386 * touching the edge of the display. */
387int32_t motion_event_get_edge_flags(const input_event_t* motion_event);
388
389/* Get the time when the user originally pressed down to start a stream of
390 * position events, in the java.lang.System.nanoTime() time base. */
391int64_t motion_event_get_down_time(const input_event_t* motion_event);
392
393/* Get the time when this specific event was generated,
394 * in the java.lang.System.nanoTime() time base. */
395int64_t motion_event_get_event_time(const input_event_t* motion_event);
396
Jeff Brown5c225b12010-06-16 01:53:36 -0700397/* Get the X coordinate offset.
398 * For touch events on the screen, this is the delta that was added to the raw
399 * screen coordinates to adjust for the absolute position of the containing windows
400 * and views. */
401float motion_event_get_x_offset(const input_event_t* motion_event);
402
403/* Get the precision of the Y coordinates being reported.
404 * For touch events on the screen, this is the delta that was added to the raw
405 * screen coordinates to adjust for the absolute position of the containing windows
406 * and views. */
407float motion_event_get_y_offset(const input_event_t* motion_event);
408
Jeff Brown46b9ac02010-04-22 18:58:52 -0700409/* Get the precision of the X coordinates being reported.
410 * You can multiply this number with an X coordinate sample to find the
411 * actual hardware value of the X coordinate. */
412float motion_event_get_x_precision(const input_event_t* motion_event);
413
414/* Get the precision of the Y coordinates being reported.
415 * You can multiply this number with a Y coordinate sample to find the
416 * actual hardware value of the Y coordinate. */
417float motion_event_get_y_precision(const input_event_t* motion_event);
418
419/* Get the number of pointers of data contained in this event.
420 * Always >= 1. */
421size_t motion_event_get_pointer_count(const input_event_t* motion_event);
422
423/* Get the pointer identifier associated with a particular pointer
424 * data index is this event. The identifier tells you the actual pointer
425 * number associated with the data, accounting for individual pointers
426 * going up and down since the start of the current gesture. */
427int32_t motion_event_get_pointer_id(const input_event_t* motion_event, size_t pointer_index);
428
Jeff Brown5c225b12010-06-16 01:53:36 -0700429/* Get the original raw X coordinate of this event.
430 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700431 * on the screen, before it had been adjusted for the containing window
432 * and views. */
Jeff Brown5c225b12010-06-16 01:53:36 -0700433float motion_event_get_raw_x(const input_event_t* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700434
Jeff Brown5c225b12010-06-16 01:53:36 -0700435/* Get the original raw X coordinate of this event.
436 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700437 * on the screen, before it had been adjusted for the containing window
438 * and views. */
Jeff Brown5c225b12010-06-16 01:53:36 -0700439float motion_event_get_raw_y(const input_event_t* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700440
441/* Get the current X coordinate of this event for the given pointer index.
442 * Whole numbers are pixels; the value may have a fraction for input devices
443 * that are sub-pixel precise. */
444float motion_event_get_x(const input_event_t* motion_event, size_t pointer_index);
445
446/* Get the current Y coordinate of this event for the given pointer index.
447 * Whole numbers are pixels; the value may have a fraction for input devices
448 * that are sub-pixel precise. */
449float motion_event_get_y(const input_event_t* motion_event, size_t pointer_index);
450
451/* Get the current pressure of this event for the given pointer index.
452 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
453 * however values higher than 1 may be generated depending on the calibration of
454 * the input device. */
455float motion_event_get_pressure(const input_event_t* motion_event, size_t pointer_index);
456
457/* Get the current scaled value of the approximate size for the given pointer index.
458 * This represents some approximation of the area of the screen being
459 * pressed; the actual value in pixels corresponding to the
460 * touch is normalized with the device specific range of values
461 * and scaled to a value between 0 and 1. The value of size can be used to
462 * determine fat touch events. */
463float motion_event_get_size(const input_event_t* motion_event, size_t pointer_index);
464
465/* Get the number of historical points in this event. These are movements that
466 * have occurred between this event and the previous event. This only applies
467 * to MOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
468 * Historical samples are indexed from oldest to newest. */
469size_t motion_event_get_history_size(const input_event_t* motion_event);
470
471/* Get the time that a historical movement occurred between this event and
472 * the previous event, in the java.lang.System.nanoTime() time base. */
473int64_t motion_event_get_historical_event_time(input_event_t* motion_event,
474 size_t history_index);
475
Jeff Brown5c225b12010-06-16 01:53:36 -0700476/* Get the historical raw X coordinate of this event for the given pointer index that
477 * occurred between this event and the previous motion event.
478 * For touch events on the screen, this is the original location of the event
479 * on the screen, before it had been adjusted for the containing window
480 * and views.
481 * Whole numbers are pixels; the value may have a fraction for input devices
482 * that are sub-pixel precise. */
483float motion_event_get_historical_raw_x(const input_event_t* motion_event, size_t pointer_index);
484
485/* Get the historical raw Y coordinate of this event for the given pointer index that
486 * occurred between this event and the previous motion event.
487 * For touch events on the screen, this is the original location of the event
488 * on the screen, before it had been adjusted for the containing window
489 * and views.
490 * Whole numbers are pixels; the value may have a fraction for input devices
491 * that are sub-pixel precise. */
492float motion_event_get_historical_raw_y(const input_event_t* motion_event, size_t pointer_index);
493
Jeff Brown46b9ac02010-04-22 18:58:52 -0700494/* Get the historical X coordinate of this event for the given pointer index that
495 * occurred between this event and the previous motion event.
496 * Whole numbers are pixels; the value may have a fraction for input devices
497 * that are sub-pixel precise. */
498float motion_event_get_historical_x(input_event_t* motion_event, size_t pointer_index,
499 size_t history_index);
500
501/* Get the historical Y coordinate of this event for the given pointer index that
502 * occurred between this event and the previous motion event.
503 * Whole numbers are pixels; the value may have a fraction for input devices
504 * that are sub-pixel precise. */
505float motion_event_get_historical_y(input_event_t* motion_event, size_t pointer_index,
506 size_t history_index);
507
508/* Get the historical pressure of this event for the given pointer index that
509 * occurred between this event and the previous motion event.
510 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
511 * however values higher than 1 may be generated depending on the calibration of
512 * the input device. */
513float motion_event_get_historical_pressure(input_event_t* motion_event, size_t pointer_index,
514 size_t history_index);
515
516/* Get the current scaled value of the approximate size for the given pointer index that
517 * occurred between this event and the previous motion event.
518 * This represents some approximation of the area of the screen being
519 * pressed; the actual value in pixels corresponding to the
520 * touch is normalized with the device specific range of values
521 * and scaled to a value between 0 and 1. The value of size can be used to
522 * determine fat touch events. */
523float motion_event_get_historical_size(input_event_t* motion_event, size_t pointer_index,
524 size_t history_index);
525
526#ifdef __cplusplus
527}
528#endif
529
530#endif // _ANDROID_INPUT_H