1 /*
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 <stdint.h>
44 #include <sys/types.h>
45 #include <android/keycodes.h>
46 #include <android/looper.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /*
53  * Key states (may be returned by queries about the current state of a
54  * particular key code, scan code or switch).
55  */
56 enum {
57     /* The key state is unknown or the requested key itself is not supported. */
58     AKEY_STATE_UNKNOWN = -1,
59 
60     /* The key is up. */
61     AKEY_STATE_UP = 0,
62 
63     /* The key is down. */
64     AKEY_STATE_DOWN = 1,
65 
66     /* The key is down but is a virtual key press that is being emulated by the system. */
67     AKEY_STATE_VIRTUAL = 2
68 };
69 
70 /*
71  * Meta key / modifer state.
72  */
73 enum {
74     /* No meta keys are pressed. */
75     AMETA_NONE = 0,
76 
77     /* This mask is used to check whether one of the ALT meta keys is pressed. */
78     AMETA_ALT_ON = 0x02,
79 
80     /* This mask is used to check whether the left ALT meta key is pressed. */
81     AMETA_ALT_LEFT_ON = 0x10,
82 
83     /* This mask is used to check whether the right ALT meta key is pressed. */
84     AMETA_ALT_RIGHT_ON = 0x20,
85 
86     /* This mask is used to check whether one of the SHIFT meta keys is pressed. */
87     AMETA_SHIFT_ON = 0x01,
88 
89     /* This mask is used to check whether the left SHIFT meta key is pressed. */
90     AMETA_SHIFT_LEFT_ON = 0x40,
91 
92     /* This mask is used to check whether the right SHIFT meta key is pressed. */
93     AMETA_SHIFT_RIGHT_ON = 0x80,
94 
95     /* This mask is used to check whether the SYM meta key is pressed. */
96     AMETA_SYM_ON = 0x04,
97 
98     /* This mask is used to check whether the FUNCTION meta key is pressed. */
99     AMETA_FUNCTION_ON = 0x08,
100 
101     /* This mask is used to check whether one of the CTRL meta keys is pressed. */
102     AMETA_CTRL_ON = 0x1000,
103 
104     /* This mask is used to check whether the left CTRL meta key is pressed. */
105     AMETA_CTRL_LEFT_ON = 0x2000,
106 
107     /* This mask is used to check whether the right CTRL meta key is pressed. */
108     AMETA_CTRL_RIGHT_ON = 0x4000,
109 
110     /* This mask is used to check whether one of the META meta keys is pressed. */
111     AMETA_META_ON = 0x10000,
112 
113     /* This mask is used to check whether the left META meta key is pressed. */
114     AMETA_META_LEFT_ON = 0x20000,
115 
116     /* This mask is used to check whether the right META meta key is pressed. */
117     AMETA_META_RIGHT_ON = 0x40000,
118 
119     /* This mask is used to check whether the CAPS LOCK meta key is on. */
120     AMETA_CAPS_LOCK_ON = 0x100000,
121 
122     /* This mask is used to check whether the NUM LOCK meta key is on. */
123     AMETA_NUM_LOCK_ON = 0x200000,
124 
125     /* This mask is used to check whether the SCROLL LOCK meta key is on. */
126     AMETA_SCROLL_LOCK_ON = 0x400000,
127 };
128 
129 /*
130  * Input events.
131  *
132  * Input events are opaque structures.  Use the provided accessors functions to
133  * read their properties.
134  */
135 struct AInputEvent;
136 typedef struct AInputEvent AInputEvent;
137 
138 /*
139  * Input event types.
140  */
141 enum {
142     /* Indicates that the input event is a key event. */
143     AINPUT_EVENT_TYPE_KEY = 1,
144 
145     /* Indicates that the input event is a motion event. */
146     AINPUT_EVENT_TYPE_MOTION = 2
147 };
148 
149 /*
150  * Key event actions.
151  */
152 enum {
153     /* The key has been pressed down. */
154     AKEY_EVENT_ACTION_DOWN = 0,
155 
156     /* The key has been released. */
157     AKEY_EVENT_ACTION_UP = 1,
158 
159     /* Multiple duplicate key events have occurred in a row, or a complex string is
160      * being delivered.  The repeat_count property of the key event contains the number
161      * of times the given key code should be executed.
162      */
163     AKEY_EVENT_ACTION_MULTIPLE = 2
164 };
165 
166 /*
167  * Key event flags.
168  */
169 enum {
170     /* This mask is set if the device woke because of this key event. */
171     AKEY_EVENT_FLAG_WOKE_HERE = 0x1,
172 
173     /* This mask is set if the key event was generated by a software keyboard. */
174     AKEY_EVENT_FLAG_SOFT_KEYBOARD = 0x2,
175 
176     /* This mask is set if we don't want the key event to cause us to leave touch mode. */
177     AKEY_EVENT_FLAG_KEEP_TOUCH_MODE = 0x4,
178 
179     /* This mask is set if an event was known to come from a trusted part
180      * of the system.  That is, the event is known to come from the user,
181      * and could not have been spoofed by a third party component. */
182     AKEY_EVENT_FLAG_FROM_SYSTEM = 0x8,
183 
184     /* This mask is used for compatibility, to identify enter keys that are
185      * coming from an IME whose enter key has been auto-labelled "next" or
186      * "done".  This allows TextView to dispatch these as normal enter keys
187      * for old applications, but still do the appropriate action when
188      * receiving them. */
189     AKEY_EVENT_FLAG_EDITOR_ACTION = 0x10,
190 
191     /* When associated with up key events, this indicates that the key press
192      * has been canceled.  Typically this is used with virtual touch screen
193      * keys, where the user can slide from the virtual key area on to the
194      * display: in that case, the application will receive a canceled up
195      * event and should not perform the action normally associated with the
196      * key.  Note that for this to work, the application can not perform an
197      * action for a key until it receives an up or the long press timeout has
198      * expired. */
199     AKEY_EVENT_FLAG_CANCELED = 0x20,
200 
201     /* This key event was generated by a virtual (on-screen) hard key area.
202      * Typically this is an area of the touchscreen, outside of the regular
203      * display, dedicated to "hardware" buttons. */
204     AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY = 0x40,
205 
206     /* This flag is set for the first key repeat that occurs after the
207      * long press timeout. */
208     AKEY_EVENT_FLAG_LONG_PRESS = 0x80,
209 
210     /* Set when a key event has AKEY_EVENT_FLAG_CANCELED set because a long
211      * press action was executed while it was down. */
212     AKEY_EVENT_FLAG_CANCELED_LONG_PRESS = 0x100,
213 
214     /* Set for AKEY_EVENT_ACTION_UP when this event's key code is still being
215      * tracked from its initial down.  That is, somebody requested that tracking
216      * started on the key down and a long press has not caused
217      * the tracking to be canceled. */
218     AKEY_EVENT_FLAG_TRACKING = 0x200,
219 
220     /* Set when a key event has been synthesized to implement default behavior
221      * for an event that the application did not handle.
222      * Fallback key events are generated by unhandled trackball motions
223      * (to emulate a directional keypad) and by certain unhandled key presses
224      * that are declared in the key map (such as special function numeric keypad
225      * keys when numlock is off). */
226     AKEY_EVENT_FLAG_FALLBACK = 0x400,
227 };
228 
229 /*
230  * Motion event actions.
231  */
232 
233 /* Bit shift for the action bits holding the pointer index as
234  * defined by AMOTION_EVENT_ACTION_POINTER_INDEX_MASK.
235  */
236 #define AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8
237 
238 enum {
239     /* Bit mask of the parts of the action code that are the action itself.
240      */
241     AMOTION_EVENT_ACTION_MASK = 0xff,
242 
243     /* Bits in the action code that represent a pointer index, used with
244      * AMOTION_EVENT_ACTION_POINTER_DOWN and AMOTION_EVENT_ACTION_POINTER_UP.  Shifting
245      * down by AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer
246      * index where the data for the pointer going up or down can be found.
247      */
248     AMOTION_EVENT_ACTION_POINTER_INDEX_MASK  = 0xff00,
249 
250     /* A pressed gesture has started, the motion contains the initial starting location.
251      */
252     AMOTION_EVENT_ACTION_DOWN = 0,
253 
254     /* A pressed gesture has finished, the motion contains the final release location
255      * as well as any intermediate points since the last down or move event.
256      */
257     AMOTION_EVENT_ACTION_UP = 1,
258 
259     /* A change has happened during a press gesture (between AMOTION_EVENT_ACTION_DOWN and
260      * AMOTION_EVENT_ACTION_UP).  The motion contains the most recent point, as well as
261      * any intermediate points since the last down or move event.
262      */
263     AMOTION_EVENT_ACTION_MOVE = 2,
264 
265     /* The current gesture has been aborted.
266      * You will not receive any more points in it.  You should treat this as
267      * an up event, but not perform any action that you normally would.
268      */
269     AMOTION_EVENT_ACTION_CANCEL = 3,
270 
271     /* A movement has happened outside of the normal bounds of the UI element.
272      * This does not provide a full gesture, but only the initial location of the movement/touch.
273      */
274     AMOTION_EVENT_ACTION_OUTSIDE = 4,
275 
276     /* A non-primary pointer has gone down.
277      * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
278      */
279     AMOTION_EVENT_ACTION_POINTER_DOWN = 5,
280 
281     /* A non-primary pointer has gone up.
282      * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
283      */
284     AMOTION_EVENT_ACTION_POINTER_UP = 6,
285 
286     /* A change happened but the pointer is not down (unlike AMOTION_EVENT_ACTION_MOVE).
287      * The motion contains the most recent point, as well as any intermediate points since
288      * the last hover move event.
289      */
290     AMOTION_EVENT_ACTION_HOVER_MOVE = 7,
291 
292     /* The motion event contains relative vertical and/or horizontal scroll offsets.
293      * Use getAxisValue to retrieve the information from AMOTION_EVENT_AXIS_VSCROLL
294      * and AMOTION_EVENT_AXIS_HSCROLL.
295      * The pointer may or may not be down when this event is dispatched.
296      * This action is always delivered to the winder under the pointer, which
297      * may not be the window currently touched.
298      */
299     AMOTION_EVENT_ACTION_SCROLL = 8,
300 
301     /* The pointer is not down but has entered the boundaries of a window or view.
302      */
303     AMOTION_EVENT_ACTION_HOVER_ENTER = 9,
304 
305     /* The pointer is not down but has exited the boundaries of a window or view.
306      */
307     AMOTION_EVENT_ACTION_HOVER_EXIT = 10,
308 
309     /* One or more buttons have been pressed. */
310     AMOTION_EVENT_ACTION_BUTTON_PRESS = 11,
311 
312     /* One or more buttons have been released. */
313     AMOTION_EVENT_ACTION_BUTTON_RELEASE = 12,
314 };
315 
316 /*
317  * Motion event flags.
318  */
319 enum {
320     /* This flag indicates that the window that received this motion event is partly
321      * or wholly obscured by another visible window above it.  This flag is set to true
322      * even if the event did not directly pass through the obscured area.
323      * A security sensitive application can check this flag to identify situations in which
324      * a malicious application may have covered up part of its content for the purpose
325      * of misleading the user or hijacking touches.  An appropriate response might be
326      * to drop the suspect touches or to take additional precautions to confirm the user's
327      * actual intent.
328      */
329     AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED = 0x1,
330 };
331 
332 /*
333  * Motion event edge touch flags.
334  */
335 enum {
336     /* No edges intersected */
337     AMOTION_EVENT_EDGE_FLAG_NONE = 0,
338 
339     /* Flag indicating the motion event intersected the top edge of the screen. */
340     AMOTION_EVENT_EDGE_FLAG_TOP = 0x01,
341 
342     /* Flag indicating the motion event intersected the bottom edge of the screen. */
343     AMOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02,
344 
345     /* Flag indicating the motion event intersected the left edge of the screen. */
346     AMOTION_EVENT_EDGE_FLAG_LEFT = 0x04,
347 
348     /* Flag indicating the motion event intersected the right edge of the screen. */
349     AMOTION_EVENT_EDGE_FLAG_RIGHT = 0x08
350 };
351 
352 /*
353  * Constants that identify each individual axis of a motion event.
354  * Refer to the documentation on the MotionEvent class for descriptions of each axis.
355  */
356 enum {
357     AMOTION_EVENT_AXIS_X = 0,
358     AMOTION_EVENT_AXIS_Y = 1,
359     AMOTION_EVENT_AXIS_PRESSURE = 2,
360     AMOTION_EVENT_AXIS_SIZE = 3,
361     AMOTION_EVENT_AXIS_TOUCH_MAJOR = 4,
362     AMOTION_EVENT_AXIS_TOUCH_MINOR = 5,
363     AMOTION_EVENT_AXIS_TOOL_MAJOR = 6,
364     AMOTION_EVENT_AXIS_TOOL_MINOR = 7,
365     AMOTION_EVENT_AXIS_ORIENTATION = 8,
366     AMOTION_EVENT_AXIS_VSCROLL = 9,
367     AMOTION_EVENT_AXIS_HSCROLL = 10,
368     AMOTION_EVENT_AXIS_Z = 11,
369     AMOTION_EVENT_AXIS_RX = 12,
370     AMOTION_EVENT_AXIS_RY = 13,
371     AMOTION_EVENT_AXIS_RZ = 14,
372     AMOTION_EVENT_AXIS_HAT_X = 15,
373     AMOTION_EVENT_AXIS_HAT_Y = 16,
374     AMOTION_EVENT_AXIS_LTRIGGER = 17,
375     AMOTION_EVENT_AXIS_RTRIGGER = 18,
376     AMOTION_EVENT_AXIS_THROTTLE = 19,
377     AMOTION_EVENT_AXIS_RUDDER = 20,
378     AMOTION_EVENT_AXIS_WHEEL = 21,
379     AMOTION_EVENT_AXIS_GAS = 22,
380     AMOTION_EVENT_AXIS_BRAKE = 23,
381     AMOTION_EVENT_AXIS_DISTANCE = 24,
382     AMOTION_EVENT_AXIS_TILT = 25,
383     AMOTION_EVENT_AXIS_GENERIC_1 = 32,
384     AMOTION_EVENT_AXIS_GENERIC_2 = 33,
385     AMOTION_EVENT_AXIS_GENERIC_3 = 34,
386     AMOTION_EVENT_AXIS_GENERIC_4 = 35,
387     AMOTION_EVENT_AXIS_GENERIC_5 = 36,
388     AMOTION_EVENT_AXIS_GENERIC_6 = 37,
389     AMOTION_EVENT_AXIS_GENERIC_7 = 38,
390     AMOTION_EVENT_AXIS_GENERIC_8 = 39,
391     AMOTION_EVENT_AXIS_GENERIC_9 = 40,
392     AMOTION_EVENT_AXIS_GENERIC_10 = 41,
393     AMOTION_EVENT_AXIS_GENERIC_11 = 42,
394     AMOTION_EVENT_AXIS_GENERIC_12 = 43,
395     AMOTION_EVENT_AXIS_GENERIC_13 = 44,
396     AMOTION_EVENT_AXIS_GENERIC_14 = 45,
397     AMOTION_EVENT_AXIS_GENERIC_15 = 46,
398     AMOTION_EVENT_AXIS_GENERIC_16 = 47,
399 
400     // NOTE: If you add a new axis here you must also add it to several other files.
401     //       Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
402 };
403 
404 /*
405  * Constants that identify buttons that are associated with motion events.
406  * Refer to the documentation on the MotionEvent class for descriptions of each button.
407  */
408 enum {
409     AMOTION_EVENT_BUTTON_PRIMARY = 1 << 0,
410     AMOTION_EVENT_BUTTON_SECONDARY = 1 << 1,
411     AMOTION_EVENT_BUTTON_TERTIARY = 1 << 2,
412     AMOTION_EVENT_BUTTON_BACK = 1 << 3,
413     AMOTION_EVENT_BUTTON_FORWARD = 1 << 4,
414     AMOTION_EVENT_BUTTON_STYLUS_PRIMARY = 1 << 5,
415     AMOTION_EVENT_BUTTON_STYLUS_SECONDARY = 1 << 6,
416 };
417 
418 /*
419  * Constants that identify tool types.
420  * Refer to the documentation on the MotionEvent class for descriptions of each tool type.
421  */
422 enum {
423     AMOTION_EVENT_TOOL_TYPE_UNKNOWN = 0,
424     AMOTION_EVENT_TOOL_TYPE_FINGER = 1,
425     AMOTION_EVENT_TOOL_TYPE_STYLUS = 2,
426     AMOTION_EVENT_TOOL_TYPE_MOUSE = 3,
427     AMOTION_EVENT_TOOL_TYPE_ERASER = 4,
428 };
429 
430 /*
431  * Input sources.
432  *
433  * Refer to the documentation on android.view.InputDevice for more details about input sources
434  * and their correct interpretation.
435  */
436 enum {
437     AINPUT_SOURCE_CLASS_MASK = 0x000000ff,
438 
439     AINPUT_SOURCE_CLASS_NONE = 0x00000000,
440     AINPUT_SOURCE_CLASS_BUTTON = 0x00000001,
441     AINPUT_SOURCE_CLASS_POINTER = 0x00000002,
442     AINPUT_SOURCE_CLASS_NAVIGATION = 0x00000004,
443     AINPUT_SOURCE_CLASS_POSITION = 0x00000008,
444     AINPUT_SOURCE_CLASS_JOYSTICK = 0x00000010,
445 };
446 
447 enum {
448     AINPUT_SOURCE_UNKNOWN = 0x00000000,
449 
450     AINPUT_SOURCE_KEYBOARD = 0x00000100 | AINPUT_SOURCE_CLASS_BUTTON,
451     AINPUT_SOURCE_DPAD = 0x00000200 | AINPUT_SOURCE_CLASS_BUTTON,
452     AINPUT_SOURCE_GAMEPAD = 0x00000400 | AINPUT_SOURCE_CLASS_BUTTON,
453     AINPUT_SOURCE_TOUCHSCREEN = 0x00001000 | AINPUT_SOURCE_CLASS_POINTER,
454     AINPUT_SOURCE_MOUSE = 0x00002000 | AINPUT_SOURCE_CLASS_POINTER,
455     AINPUT_SOURCE_STYLUS = 0x00004000 | AINPUT_SOURCE_CLASS_POINTER,
456     AINPUT_SOURCE_BLUETOOTH_STYLUS = 0x00008000 | AINPUT_SOURCE_STYLUS,
457     AINPUT_SOURCE_TRACKBALL = 0x00010000 | AINPUT_SOURCE_CLASS_NAVIGATION,
458     AINPUT_SOURCE_TOUCHPAD = 0x00100000 | AINPUT_SOURCE_CLASS_POSITION,
459     AINPUT_SOURCE_TOUCH_NAVIGATION = 0x00200000 | AINPUT_SOURCE_CLASS_NONE,
460     AINPUT_SOURCE_JOYSTICK = 0x01000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
461 
462     AINPUT_SOURCE_ANY = 0xffffff00,
463 };
464 
465 /*
466  * Keyboard types.
467  *
468  * Refer to the documentation on android.view.InputDevice for more details.
469  */
470 enum {
471     AINPUT_KEYBOARD_TYPE_NONE = 0,
472     AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC = 1,
473     AINPUT_KEYBOARD_TYPE_ALPHABETIC = 2,
474 };
475 
476 /*
477  * Constants used to retrieve information about the range of motion for a particular
478  * coordinate of a motion event.
479  *
480  * Refer to the documentation on android.view.InputDevice for more details about input sources
481  * and their correct interpretation.
482  *
483  * DEPRECATION NOTICE: These constants are deprecated.  Use AMOTION_EVENT_AXIS_* constants instead.
484  */
485 enum {
486     AINPUT_MOTION_RANGE_X = AMOTION_EVENT_AXIS_X,
487     AINPUT_MOTION_RANGE_Y = AMOTION_EVENT_AXIS_Y,
488     AINPUT_MOTION_RANGE_PRESSURE = AMOTION_EVENT_AXIS_PRESSURE,
489     AINPUT_MOTION_RANGE_SIZE = AMOTION_EVENT_AXIS_SIZE,
490     AINPUT_MOTION_RANGE_TOUCH_MAJOR = AMOTION_EVENT_AXIS_TOUCH_MAJOR,
491     AINPUT_MOTION_RANGE_TOUCH_MINOR = AMOTION_EVENT_AXIS_TOUCH_MINOR,
492     AINPUT_MOTION_RANGE_TOOL_MAJOR = AMOTION_EVENT_AXIS_TOOL_MAJOR,
493     AINPUT_MOTION_RANGE_TOOL_MINOR = AMOTION_EVENT_AXIS_TOOL_MINOR,
494     AINPUT_MOTION_RANGE_ORIENTATION = AMOTION_EVENT_AXIS_ORIENTATION,
495 } __attribute__ ((deprecated));
496 
497 
498 /*
499  * Input event accessors.
500  *
501  * Note that most functions can only be used on input events that are of a given type.
502  * Calling these functions on input events of other types will yield undefined behavior.
503  */
504 
505 /*** Accessors for all input events. ***/
506 
507 /* Get the input event type. */
508 int32_t AInputEvent_getType(const AInputEvent* event);
509 
510 /* Get the id for the device that an input event came from.
511  *
512  * Input events can be generated by multiple different input devices.
513  * Use the input device id to obtain information about the input
514  * device that was responsible for generating a particular event.
515  *
516  * An input device id of 0 indicates that the event didn't come from a physical device;
517  * other numbers are arbitrary and you shouldn't depend on the values.
518  * Use the provided input device query API to obtain information about input devices.
519  */
520 int32_t AInputEvent_getDeviceId(const AInputEvent* event);
521 
522 /* Get the input event source. */
523 int32_t AInputEvent_getSource(const AInputEvent* event);
524 
525 /*** Accessors for key events only. ***/
526 
527 /* Get the key event action. */
528 int32_t AKeyEvent_getAction(const AInputEvent* key_event);
529 
530 /* Get the key event flags. */
531 int32_t AKeyEvent_getFlags(const AInputEvent* key_event);
532 
533 /* Get the key code of the key event.
534  * This is the physical key that was pressed, not the Unicode character. */
535 int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event);
536 
537 /* Get the hardware key id of this key event.
538  * These values are not reliable and vary from device to device. */
539 int32_t AKeyEvent_getScanCode(const AInputEvent* key_event);
540 
541 /* Get the meta key state. */
542 int32_t AKeyEvent_getMetaState(const AInputEvent* key_event);
543 
544 /* Get the repeat count of the event.
545  * For both key up an key down events, this is the number of times the key has
546  * repeated with the first down starting at 0 and counting up from there.  For
547  * multiple key events, this is the number of down/up pairs that have occurred. */
548 int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event);
549 
550 /* Get the time of the most recent key down event, in the
551  * java.lang.System.nanoTime() time base.  If this is a down event,
552  * this will be the same as eventTime.
553  * Note that when chording keys, this value is the down time of the most recently
554  * pressed key, which may not be the same physical key of this event. */
555 int64_t AKeyEvent_getDownTime(const AInputEvent* key_event);
556 
557 /* Get the time this event occurred, in the
558  * java.lang.System.nanoTime() time base. */
559 int64_t AKeyEvent_getEventTime(const AInputEvent* key_event);
560 
561 /*** Accessors for motion events only. ***/
562 
563 /* Get the combined motion event action code and pointer index. */
564 int32_t AMotionEvent_getAction(const AInputEvent* motion_event);
565 
566 /* Get the motion event flags. */
567 int32_t AMotionEvent_getFlags(const AInputEvent* motion_event);
568 
569 /* Get the state of any meta / modifier keys that were in effect when the
570  * event was generated. */
571 int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
572 
573 /* Get the button state of all buttons that are pressed. */
574 int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event);
575 
576 /* Get a bitfield indicating which edges, if any, were touched by this motion event.
577  * For touch events, clients can use this to determine if the user's finger was
578  * touching the edge of the display. */
579 int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event);
580 
581 /* Get the time when the user originally pressed down to start a stream of
582  * position events, in the java.lang.System.nanoTime() time base. */
583 int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event);
584 
585 /* Get the time when this specific event was generated,
586  * in the java.lang.System.nanoTime() time base. */
587 int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event);
588 
589 /* Get the X coordinate offset.
590  * For touch events on the screen, this is the delta that was added to the raw
591  * screen coordinates to adjust for the absolute position of the containing windows
592  * and views. */
593 float AMotionEvent_getXOffset(const AInputEvent* motion_event);
594 
595 /* Get the Y coordinate offset.
596  * For touch events on the screen, this is the delta that was added to the raw
597  * screen coordinates to adjust for the absolute position of the containing windows
598  * and views. */
599 float AMotionEvent_getYOffset(const AInputEvent* motion_event);
600 
601 /* Get the precision of the X coordinates being reported.
602  * You can multiply this number with an X coordinate sample to find the
603  * actual hardware value of the X coordinate. */
604 float AMotionEvent_getXPrecision(const AInputEvent* motion_event);
605 
606 /* Get the precision of the Y coordinates being reported.
607  * You can multiply this number with a Y coordinate sample to find the
608  * actual hardware value of the Y coordinate. */
609 float AMotionEvent_getYPrecision(const AInputEvent* motion_event);
610 
611 /* Get the number of pointers of data contained in this event.
612  * Always >= 1. */
613 size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event);
614 
615 /* Get the pointer identifier associated with a particular pointer
616  * data index in this event.  The identifier tells you the actual pointer
617  * number associated with the data, accounting for individual pointers
618  * going up and down since the start of the current gesture. */
619 int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
620 
621 /* Get the tool type of a pointer for the given pointer index.
622  * The tool type indicates the type of tool used to make contact such as a
623  * finger or stylus, if known. */
624 int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index);
625 
626 /* Get the original raw X coordinate of this event.
627  * For touch events on the screen, this is the original location of the event
628  * on the screen, before it had been adjusted for the containing window
629  * and views. */
630 float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index);
631 
632 /* Get the original raw X coordinate of this event.
633  * For touch events on the screen, this is the original location of the event
634  * on the screen, before it had been adjusted for the containing window
635  * and views. */
636 float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index);
637 
638 /* Get the current X coordinate of this event for the given pointer index.
639  * Whole numbers are pixels; the value may have a fraction for input devices
640  * that are sub-pixel precise. */
641 float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index);
642 
643 /* Get the current Y coordinate of this event for the given pointer index.
644  * Whole numbers are pixels; the value may have a fraction for input devices
645  * that are sub-pixel precise. */
646 float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
647 
648 /* Get the current pressure of this event for the given pointer index.
649  * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
650  * although values higher than 1 may be generated depending on the calibration of
651  * the input device. */
652 float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
653 
654 /* Get the current scaled value of the approximate size for the given pointer index.
655  * This represents some approximation of the area of the screen being
656  * pressed; the actual value in pixels corresponding to the
657  * touch is normalized with the device specific range of values
658  * and scaled to a value between 0 and 1.  The value of size can be used to
659  * determine fat touch events. */
660 float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index);
661 
662 /* Get the current length of the major axis of an ellipse that describes the touch area
663  * at the point of contact for the given pointer index. */
664 float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index);
665 
666 /* Get the current length of the minor axis of an ellipse that describes the touch area
667  * at the point of contact for the given pointer index. */
668 float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index);
669 
670 /* Get the current length of the major axis of an ellipse that describes the size
671  * of the approaching tool for the given pointer index.
672  * The tool area represents the estimated size of the finger or pen that is
673  * touching the device independent of its actual touch area at the point of contact. */
674 float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index);
675 
676 /* Get the current length of the minor axis of an ellipse that describes the size
677  * of the approaching tool for the given pointer index.
678  * The tool area represents the estimated size of the finger or pen that is
679  * touching the device independent of its actual touch area at the point of contact. */
680 float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index);
681 
682 /* Get the current orientation of the touch area and tool area in radians clockwise from
683  * vertical for the given pointer index.
684  * An angle of 0 degrees indicates that the major axis of contact is oriented
685  * upwards, is perfectly circular or is of unknown orientation.  A positive angle
686  * indicates that the major axis of contact is oriented to the right.  A negative angle
687  * indicates that the major axis of contact is oriented to the left.
688  * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
689  * (finger pointing fully right). */
690 float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index);
691 
692 /* Get the value of the request axis for the given pointer index. */
693 float AMotionEvent_getAxisValue(const AInputEvent* motion_event,
694         int32_t axis, size_t pointer_index);
695 
696 /* Get the number of historical points in this event.  These are movements that
697  * have occurred between this event and the previous event.  This only applies
698  * to AMOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
699  * Historical samples are indexed from oldest to newest. */
700 size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event);
701 
702 /* Get the time that a historical movement occurred between this event and
703  * the previous event, in the java.lang.System.nanoTime() time base. */
704 int64_t AMotionEvent_getHistoricalEventTime(const AInputEvent* motion_event,
705         size_t history_index);
706 
707 /* Get the historical raw X coordinate of this event for the given pointer index that
708  * occurred between this event and the previous motion event.
709  * For touch events on the screen, this is the original location of the event
710  * on the screen, before it had been adjusted for the containing window
711  * and views.
712  * Whole numbers are pixels; the value may have a fraction for input devices
713  * that are sub-pixel precise. */
714 float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index,
715         size_t history_index);
716 
717 /* Get the historical raw Y coordinate of this event for the given pointer index that
718  * occurred between this event and the previous motion event.
719  * For touch events on the screen, this is the original location of the event
720  * on the screen, before it had been adjusted for the containing window
721  * and views.
722  * Whole numbers are pixels; the value may have a fraction for input devices
723  * that are sub-pixel precise. */
724 float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index,
725         size_t history_index);
726 
727 /* Get the historical X coordinate of this event for the given pointer index that
728  * occurred between this event and the previous motion event.
729  * Whole numbers are pixels; the value may have a fraction for input devices
730  * that are sub-pixel precise. */
731 float AMotionEvent_getHistoricalX(const AInputEvent* motion_event, size_t pointer_index,
732         size_t history_index);
733 
734 /* Get the historical Y coordinate of this event for the given pointer index that
735  * occurred between this event and the previous motion event.
736  * Whole numbers are pixels; the value may have a fraction for input devices
737  * that are sub-pixel precise. */
738 float AMotionEvent_getHistoricalY(const AInputEvent* motion_event, size_t pointer_index,
739         size_t history_index);
740 
741 /* Get the historical pressure of this event for the given pointer index that
742  * occurred between this event and the previous motion event.
743  * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
744  * although values higher than 1 may be generated depending on the calibration of
745  * the input device. */
746 float AMotionEvent_getHistoricalPressure(const AInputEvent* motion_event, size_t pointer_index,
747         size_t history_index);
748 
749 /* Get the current scaled value of the approximate size for the given pointer index that
750  * occurred between this event and the previous motion event.
751  * This represents some approximation of the area of the screen being
752  * pressed; the actual value in pixels corresponding to the
753  * touch is normalized with the device specific range of values
754  * and scaled to a value between 0 and 1.  The value of size can be used to
755  * determine fat touch events. */
756 float AMotionEvent_getHistoricalSize(const AInputEvent* motion_event, size_t pointer_index,
757         size_t history_index);
758 
759 /* Get the historical length of the major axis of an ellipse that describes the touch area
760  * at the point of contact for the given pointer index that
761  * occurred between this event and the previous motion event. */
762 float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index,
763         size_t history_index);
764 
765 /* Get the historical length of the minor axis of an ellipse that describes the touch area
766  * at the point of contact for the given pointer index that
767  * occurred between this event and the previous motion event. */
768 float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index,
769         size_t history_index);
770 
771 /* Get the historical length of the major axis of an ellipse that describes the size
772  * of the approaching tool for the given pointer index that
773  * occurred between this event and the previous motion event.
774  * The tool area represents the estimated size of the finger or pen that is
775  * touching the device independent of its actual touch area at the point of contact. */
776 float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index,
777         size_t history_index);
778 
779 /* Get the historical length of the minor axis of an ellipse that describes the size
780  * of the approaching tool for the given pointer index that
781  * occurred between this event and the previous motion event.
782  * The tool area represents the estimated size of the finger or pen that is
783  * touching the device independent of its actual touch area at the point of contact. */
784 float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index,
785         size_t history_index);
786 
787 /* Get the historical orientation of the touch area and tool area in radians clockwise from
788  * vertical for the given pointer index that
789  * occurred between this event and the previous motion event.
790  * An angle of 0 degrees indicates that the major axis of contact is oriented
791  * upwards, is perfectly circular or is of unknown orientation.  A positive angle
792  * indicates that the major axis of contact is oriented to the right.  A negative angle
793  * indicates that the major axis of contact is oriented to the left.
794  * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
795  * (finger pointing fully right). */
796 float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
797         size_t history_index);
798 
799 /* Get the historical value of the request axis for the given pointer index
800  * that occurred between this event and the previous motion event. */
801 float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event,
802         int32_t axis, size_t pointer_index, size_t history_index);
803 
804 
805 /*
806  * Input queue
807  *
808  * An input queue is the facility through which you retrieve input
809  * events.
810  */
811 struct AInputQueue;
812 typedef struct AInputQueue AInputQueue;
813 
814 /*
815  * Add this input queue to a looper for processing.  See
816  * ALooper_addFd() for information on the ident, callback, and data params.
817  */
818 void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
819         int ident, ALooper_callbackFunc callback, void* data);
820 
821 /*
822  * Remove the input queue from the looper it is currently attached to.
823  */
824 void AInputQueue_detachLooper(AInputQueue* queue);
825 
826 /*
827  * Returns true if there are one or more events available in the
828  * input queue.  Returns 1 if the queue has events; 0 if
829  * it does not have events; and a negative value if there is an error.
830  */
831 int32_t AInputQueue_hasEvents(AInputQueue* queue);
832 
833 /*
834  * Returns the next available event from the queue.  Returns a negative
835  * value if no events are available or an error has occurred.
836  */
837 int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent);
838 
839 /*
840  * Sends the key for standard pre-dispatching -- that is, possibly deliver
841  * it to the current IME to be consumed before the app.  Returns 0 if it
842  * was not pre-dispatched, meaning you can process it right now.  If non-zero
843  * is returned, you must abandon the current event processing and allow the
844  * event to appear again in the event queue (if it does not get consumed during
845  * pre-dispatching).
846  */
847 int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event);
848 
849 /*
850  * Report that dispatching has finished with the given event.
851  * This must be called after receiving an event with AInputQueue_get_event().
852  */
853 void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
854 
855 #ifdef __cplusplus
856 }
857 #endif
858 
859 #endif // _ANDROID_INPUT_H
860