blob: 9883ac70a71477f2e8a7d3198c4459abcdefd61a [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>
Dianne Hackborn68267412010-07-02 18:52:01 -070045#include <android/looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070046
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/*
Jeff Brown46b9ac02010-04-22 18:58:52 -070052 * Key states (may be returned by queries about the current state of a
53 * particular key code, scan code or switch).
Jeff Brown46b9ac02010-04-22 18:58:52 -070054 */
55enum {
56 /* The key state is unknown or the requested key itself is not supported. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070057 AKEY_STATE_UNKNOWN = -1,
Jeff Brown46b9ac02010-04-22 18:58:52 -070058
59 /* The key is up. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070060 AKEY_STATE_UP = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -070061
62 /* The key is down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070063 AKEY_STATE_DOWN = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -070064
65 /* The key is down but is a virtual key press that is being emulated by the system. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070066 AKEY_STATE_VIRTUAL = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -070067};
68
69/*
70 * Meta key / modifer state.
71 */
72enum {
73 /* No meta keys are pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070074 AMETA_NONE = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -070075
76 /* This mask is used to check whether one of the ALT meta keys is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070077 AMETA_ALT_ON = 0x02,
Jeff Brown46b9ac02010-04-22 18:58:52 -070078
79 /* This mask is used to check whether the left ALT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070080 AMETA_ALT_LEFT_ON = 0x10,
Jeff Brown46b9ac02010-04-22 18:58:52 -070081
82 /* This mask is used to check whether the right ALT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070083 AMETA_ALT_RIGHT_ON = 0x20,
Jeff Brown46b9ac02010-04-22 18:58:52 -070084
85 /* This mask is used to check whether one of the SHIFT meta keys is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070086 AMETA_SHIFT_ON = 0x01,
Jeff Brown46b9ac02010-04-22 18:58:52 -070087
88 /* This mask is used to check whether the left SHIFT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070089 AMETA_SHIFT_LEFT_ON = 0x40,
Jeff Brown46b9ac02010-04-22 18:58:52 -070090
91 /* This mask is used to check whether the right SHIFT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070092 AMETA_SHIFT_RIGHT_ON = 0x80,
Jeff Brown46b9ac02010-04-22 18:58:52 -070093
94 /* This mask is used to check whether the SYM meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070095 AMETA_SYM_ON = 0x04
Jeff Brown46b9ac02010-04-22 18:58:52 -070096};
97
98/*
99 * Input events.
100 *
101 * Input events are opaque structures. Use the provided accessors functions to
102 * read their properties.
103 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700104struct AInputEvent;
105typedef struct AInputEvent AInputEvent;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700106
107/*
108 * Input event types.
109 */
110enum {
111 /* Indicates that the input event is a key event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700112 AINPUT_EVENT_TYPE_KEY = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700113
114 /* Indicates that the input event is a motion event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700115 AINPUT_EVENT_TYPE_MOTION = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -0700116};
117
118/*
119 * Key event actions.
120 */
121enum {
122 /* The key has been pressed down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700123 AKEY_EVENT_ACTION_DOWN = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700124
125 /* The key has been released. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700126 AKEY_EVENT_ACTION_UP = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700127
128 /* Multiple duplicate key events have occurred in a row, or a complex string is
129 * being delivered. The repeat_count property of the key event contains the number
130 * of times the given key code should be executed.
131 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700132 AKEY_EVENT_ACTION_MULTIPLE = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -0700133};
134
135/*
136 * Key event flags.
137 */
138enum {
139 /* This mask is set if the device woke because of this key event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700140 AKEY_EVENT_FLAG_WOKE_HERE = 0x1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700141
142 /* This mask is set if the key event was generated by a software keyboard. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700143 AKEY_EVENT_FLAG_SOFT_KEYBOARD = 0x2,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700144
145 /* This mask is set if we don't want the key event to cause us to leave touch mode. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700146 AKEY_EVENT_FLAG_KEEP_TOUCH_MODE = 0x4,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700147
148 /* This mask is set if an event was known to come from a trusted part
149 * of the system. That is, the event is known to come from the user,
150 * and could not have been spoofed by a third party component. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700151 AKEY_EVENT_FLAG_FROM_SYSTEM = 0x8,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700152
153 /* This mask is used for compatibility, to identify enter keys that are
154 * coming from an IME whose enter key has been auto-labelled "next" or
155 * "done". This allows TextView to dispatch these as normal enter keys
156 * for old applications, but still do the appropriate action when
157 * receiving them. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700158 AKEY_EVENT_FLAG_EDITOR_ACTION = 0x10,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700159
160 /* When associated with up key events, this indicates that the key press
161 * has been canceled. Typically this is used with virtual touch screen
162 * keys, where the user can slide from the virtual key area on to the
163 * display: in that case, the application will receive a canceled up
164 * event and should not perform the action normally associated with the
165 * key. Note that for this to work, the application can not perform an
166 * action for a key until it receives an up or the long press timeout has
167 * expired. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700168 AKEY_EVENT_FLAG_CANCELED = 0x20,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700169
170 /* This key event was generated by a virtual (on-screen) hard key area.
171 * Typically this is an area of the touchscreen, outside of the regular
172 * display, dedicated to "hardware" buttons. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700173 AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY = 0x40,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700174
175 /* This flag is set for the first key repeat that occurs after the
176 * long press timeout. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700177 AKEY_EVENT_FLAG_LONG_PRESS = 0x80,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700178
Jeff Brownc5ed5912010-07-14 18:48:53 -0700179 /* Set when a key event has AKEY_EVENT_FLAG_CANCELED set because a long
Jeff Brown46b9ac02010-04-22 18:58:52 -0700180 * press action was executed while it was down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700181 AKEY_EVENT_FLAG_CANCELED_LONG_PRESS = 0x100,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700182
Jeff Brownc5ed5912010-07-14 18:48:53 -0700183 /* Set for AKEY_EVENT_ACTION_UP when this event's key code is still being
Jeff Brown46b9ac02010-04-22 18:58:52 -0700184 * tracked from its initial down. That is, somebody requested that tracking
185 * started on the key down and a long press has not caused
186 * the tracking to be canceled. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700187 AKEY_EVENT_FLAG_TRACKING = 0x200
Jeff Brown46b9ac02010-04-22 18:58:52 -0700188};
189
190/*
191 * Motion event actions.
192 */
193
194/* Bit shift for the action bits holding the pointer index as
Jeff Brownc5ed5912010-07-14 18:48:53 -0700195 * defined by AMOTION_EVENT_ACTION_POINTER_INDEX_MASK.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700196 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700197#define AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8
Jeff Brown46b9ac02010-04-22 18:58:52 -0700198
199enum {
200 /* Bit mask of the parts of the action code that are the action itself.
201 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700202 AMOTION_EVENT_ACTION_MASK = 0xff,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700203
204 /* Bits in the action code that represent a pointer index, used with
Jeff Brownc5ed5912010-07-14 18:48:53 -0700205 * AMOTION_EVENT_ACTION_POINTER_DOWN and AMOTION_EVENT_ACTION_POINTER_UP. Shifting
206 * down by AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer
Jeff Brown46b9ac02010-04-22 18:58:52 -0700207 * index where the data for the pointer going up or down can be found.
208 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700209 AMOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700210
211 /* A pressed gesture has started, the motion contains the initial starting location.
212 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700213 AMOTION_EVENT_ACTION_DOWN = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700214
215 /* A pressed gesture has finished, the motion contains the final release location
216 * as well as any intermediate points since the last down or move event.
217 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700218 AMOTION_EVENT_ACTION_UP = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700219
Jeff Brownc5ed5912010-07-14 18:48:53 -0700220 /* A change has happened during a press gesture (between AMOTION_EVENT_ACTION_DOWN and
221 * AMOTION_EVENT_ACTION_UP). The motion contains the most recent point, as well as
Jeff Brown46b9ac02010-04-22 18:58:52 -0700222 * any intermediate points since the last down or move event.
223 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700224 AMOTION_EVENT_ACTION_MOVE = 2,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700225
226 /* The current gesture has been aborted.
227 * You will not receive any more points in it. You should treat this as
228 * an up event, but not perform any action that you normally would.
229 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700230 AMOTION_EVENT_ACTION_CANCEL = 3,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700231
232 /* A movement has happened outside of the normal bounds of the UI element.
233 * This does not provide a full gesture, but only the initial location of the movement/touch.
234 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700235 AMOTION_EVENT_ACTION_OUTSIDE = 4,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700236
237 /* A non-primary pointer has gone down.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700238 * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700239 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700240 AMOTION_EVENT_ACTION_POINTER_DOWN = 5,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700241
242 /* A non-primary pointer has gone up.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700243 * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700244 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700245 AMOTION_EVENT_ACTION_POINTER_UP = 6
Jeff Brown46b9ac02010-04-22 18:58:52 -0700246};
247
248/*
249 * Motion event edge touch flags.
250 */
251enum {
252 /* No edges intersected */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700253 AMOTION_EVENT_EDGE_FLAG_NONE = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700254
255 /* Flag indicating the motion event intersected the top edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700256 AMOTION_EVENT_EDGE_FLAG_TOP = 0x01,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700257
258 /* Flag indicating the motion event intersected the bottom edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700259 AMOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700260
261 /* Flag indicating the motion event intersected the left edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700262 AMOTION_EVENT_EDGE_FLAG_LEFT = 0x04,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700263
264 /* Flag indicating the motion event intersected the right edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700265 AMOTION_EVENT_EDGE_FLAG_RIGHT = 0x08
Jeff Brown46b9ac02010-04-22 18:58:52 -0700266};
267
268/*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700269 * Input sources.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700270 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700271 * Refer to the documentation on android.view.InputDevice for more details about input sources
272 * and their correct interpretation.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700273 */
274enum {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700275 AINPUT_SOURCE_CLASS_MASK = 0x000000ff,
276
277 AINPUT_SOURCE_CLASS_BUTTON = 0x00000001,
278 AINPUT_SOURCE_CLASS_POINTER = 0x00000002,
279 AINPUT_SOURCE_CLASS_NAVIGATION = 0x00000004,
280 AINPUT_SOURCE_CLASS_POSITION = 0x00000008,
281 AINPUT_SOURCE_CLASS_JOYSTICK = 0x00000010,
282};
283
284enum {
285 AINPUT_SOURCE_UNKNOWN = 0x00000000,
286
287 AINPUT_SOURCE_KEYBOARD = 0x00000100 | AINPUT_SOURCE_CLASS_BUTTON,
288 AINPUT_SOURCE_DPAD = 0x00000200 | AINPUT_SOURCE_CLASS_BUTTON,
289 AINPUT_SOURCE_GAMEPAD = 0x00000400 | AINPUT_SOURCE_CLASS_BUTTON,
290 AINPUT_SOURCE_TOUCHSCREEN = 0x00001000 | AINPUT_SOURCE_CLASS_POINTER,
291 AINPUT_SOURCE_MOUSE = 0x00002000 | AINPUT_SOURCE_CLASS_POINTER,
292 AINPUT_SOURCE_TRACKBALL = 0x00010000 | AINPUT_SOURCE_CLASS_NAVIGATION,
293 AINPUT_SOURCE_TOUCHPAD = 0x00100000 | AINPUT_SOURCE_CLASS_POSITION,
294 AINPUT_SOURCE_JOYSTICK_LEFT = 0x01000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
295 AINPUT_SOURCE_JOYSTICK_RIGHT = 0x02000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700296};
297
298/*
Jeff Brown6d0fec22010-07-23 21:28:06 -0700299 * Keyboard types.
300 *
301 * Refer to the documentation on android.view.InputDevice for more details.
302 */
303enum {
304 AINPUT_KEYBOARD_TYPE_NONE = 0,
305 AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC = 1,
306 AINPUT_KEYBOARD_TYPE_ALPHABETIC = 2,
307};
308
309/*
310 * Constants used to retrieve information about the range of motion for a particular
311 * coordinate of a motion event.
312 *
313 * Refer to the documentation on android.view.InputDevice for more details about input sources
314 * and their correct interpretation.
315 */
316enum {
317 AINPUT_MOTION_RANGE_X = 0,
318 AINPUT_MOTION_RANGE_Y = 1,
319 AINPUT_MOTION_RANGE_PRESSURE = 2,
320 AINPUT_MOTION_RANGE_SIZE = 3,
321 AINPUT_MOTION_RANGE_TOUCH_MAJOR = 4,
322 AINPUT_MOTION_RANGE_TOUCH_MINOR = 5,
323 AINPUT_MOTION_RANGE_TOOL_MAJOR = 6,
324 AINPUT_MOTION_RANGE_TOOL_MINOR = 7,
325 AINPUT_MOTION_RANGE_ORIENTATION = 8,
326};
327
328
329/*
Jeff Brown46b9ac02010-04-22 18:58:52 -0700330 * Input event accessors.
331 *
332 * Note that most functions can only be used on input events that are of a given type.
333 * Calling these functions on input events of other types will yield undefined behavior.
334 */
335
336/*** Accessors for all input events. ***/
337
338/* Get the input event type. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700339int32_t AInputEvent_getType(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700340
341/* Get the id for the device that an input event came from.
342 *
343 * Input events can be generated by multiple different input devices.
344 * Use the input device id to obtain information about the input
345 * device that was responsible for generating a particular event.
346 *
347 * An input device id of 0 indicates that the event didn't come from a physical device;
348 * other numbers are arbitrary and you shouldn't depend on the values.
349 * Use the provided input device query API to obtain information about input devices.
350 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700351int32_t AInputEvent_getDeviceId(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700352
Jeff Brownc5ed5912010-07-14 18:48:53 -0700353/* Get the input event source. */
354int32_t AInputEvent_getSource(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700355
356/*** Accessors for key events only. ***/
357
358/* Get the key event action. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700359int32_t AKeyEvent_getAction(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700360
361/* Get the key event flags. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700362int32_t AKeyEvent_getFlags(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700363
364/* Get the key code of the key event.
365 * This is the physical key that was pressed, not the Unicode character. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700366int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700367
368/* Get the hardware key id of this key event.
369 * These values are not reliable and vary from device to device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700370int32_t AKeyEvent_getScanCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700371
372/* Get the meta key state. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700373int32_t AKeyEvent_getMetaState(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700374
375/* Get the repeat count of the event.
376 * For both key up an key down events, this is the number of times the key has
377 * repeated with the first down starting at 0 and counting up from there. For
378 * multiple key events, this is the number of down/up pairs that have occurred. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700379int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700380
381/* Get the time of the most recent key down event, in the
382 * java.lang.System.nanoTime() time base. If this is a down event,
383 * this will be the same as eventTime.
384 * Note that when chording keys, this value is the down time of the most recently
385 * pressed key, which may not be the same physical key of this event. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700386int64_t AKeyEvent_getDownTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700387
388/* Get the time this event occurred, in the
389 * java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700390int64_t AKeyEvent_getEventTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700391
392/*** Accessors for motion events only. ***/
393
394/* Get the combined motion event action code and pointer index. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700395int32_t AMotionEvent_getAction(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700396
397/* Get the state of any meta / modifier keys that were in effect when the
398 * event was generated. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700399int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700400
401/* Get a bitfield indicating which edges, if any, were touched by this motion event.
402 * For touch events, clients can use this to determine if the user's finger was
403 * touching the edge of the display. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700404int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700405
406/* Get the time when the user originally pressed down to start a stream of
407 * position events, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700408int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700409
410/* Get the time when this specific event was generated,
411 * in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700412int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700413
Jeff Brown5c225b12010-06-16 01:53:36 -0700414/* Get the X coordinate offset.
415 * For touch events on the screen, this is the delta that was added to the raw
416 * screen coordinates to adjust for the absolute position of the containing windows
417 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700418float AMotionEvent_getXOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700419
420/* Get the precision of the Y coordinates being reported.
421 * For touch events on the screen, this is the delta that was added to the raw
422 * screen coordinates to adjust for the absolute position of the containing windows
423 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700424float AMotionEvent_getYOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700425
Jeff Brown46b9ac02010-04-22 18:58:52 -0700426/* Get the precision of the X coordinates being reported.
427 * You can multiply this number with an X coordinate sample to find the
428 * actual hardware value of the X coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700429float AMotionEvent_getXPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700430
431/* Get the precision of the Y coordinates being reported.
432 * You can multiply this number with a Y coordinate sample to find the
433 * actual hardware value of the Y coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700434float AMotionEvent_getYPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700435
436/* Get the number of pointers of data contained in this event.
437 * Always >= 1. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700438size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700439
440/* Get the pointer identifier associated with a particular pointer
441 * data index is this event. The identifier tells you the actual pointer
442 * number associated with the data, accounting for individual pointers
443 * going up and down since the start of the current gesture. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700444int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700445
Jeff Brown5c225b12010-06-16 01:53:36 -0700446/* Get the original raw X coordinate of this event.
447 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700448 * on the screen, before it had been adjusted for the containing window
449 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700450float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700451
Jeff Brown5c225b12010-06-16 01:53:36 -0700452/* Get the original raw X coordinate of this event.
453 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700454 * on the screen, before it had been adjusted for the containing window
455 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700456float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700457
458/* Get the current X coordinate of this event for the given pointer index.
459 * Whole numbers are pixels; the value may have a fraction for input devices
460 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700461float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700462
463/* Get the current Y coordinate of this event for the given pointer index.
464 * Whole numbers are pixels; the value may have a fraction for input devices
465 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700466float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700467
468/* Get the current pressure of this event for the given pointer index.
469 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
470 * however values higher than 1 may be generated depending on the calibration of
471 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700472float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700473
474/* Get the current scaled value of the approximate size for the given pointer index.
475 * This represents some approximation of the area of the screen being
476 * pressed; the actual value in pixels corresponding to the
477 * touch is normalized with the device specific range of values
478 * and scaled to a value between 0 and 1. The value of size can be used to
479 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700480float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700481
Jeff Brownc5ed5912010-07-14 18:48:53 -0700482/* Get the current length of the major axis of an ellipse that describes the touch area
483 * at the point of contact for the given pointer index. */
484float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index);
485
486/* Get the current length of the minor axis of an ellipse that describes the touch area
487 * at the point of contact for the given pointer index. */
488float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index);
489
490/* Get the current length of the major axis of an ellipse that describes the size
491 * of the approaching tool for the given pointer index.
492 * The tool area represents the estimated size of the finger or pen that is
493 * touching the device independent of its actual touch area at the point of contact. */
494float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index);
495
496/* Get the current length of the minor axis of an ellipse that describes the size
497 * of the approaching tool for the given pointer index.
498 * The tool area represents the estimated size of the finger or pen that is
499 * touching the device independent of its actual touch area at the point of contact. */
500float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index);
501
502/* Get the current orientation of the touch area and tool area in radians clockwise from
503 * vertical for the given pointer index.
504 * An angle of 0 degrees indicates that the major axis of contact is oriented
505 * upwards, is perfectly circular or is of unknown orientation. A positive angle
506 * indicates that the major axis of contact is oriented to the right. A negative angle
507 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700508 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700509 * (finger pointing fully right). */
510float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index);
511
Jeff Brown46b9ac02010-04-22 18:58:52 -0700512/* Get the number of historical points in this event. These are movements that
513 * have occurred between this event and the previous event. This only applies
Jeff Brownc5ed5912010-07-14 18:48:53 -0700514 * to AMOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700515 * Historical samples are indexed from oldest to newest. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700516size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700517
518/* Get the time that a historical movement occurred between this event and
519 * the previous event, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700520int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700521 size_t history_index);
522
Jeff Brown5c225b12010-06-16 01:53:36 -0700523/* Get the historical raw X coordinate of this event for the given pointer index that
524 * occurred between this event and the previous motion event.
525 * For touch events on the screen, this is the original location of the event
526 * on the screen, before it had been adjusted for the containing window
527 * and views.
528 * Whole numbers are pixels; the value may have a fraction for input devices
529 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700530float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700531
532/* Get the historical raw Y coordinate of this event for the given pointer index that
533 * occurred between this event and the previous motion event.
534 * For touch events on the screen, this is the original location of the event
535 * on the screen, before it had been adjusted for the containing window
536 * and views.
537 * Whole numbers are pixels; the value may have a fraction for input devices
538 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700539float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700540
Jeff Brown46b9ac02010-04-22 18:58:52 -0700541/* Get the historical X coordinate of this event for the given pointer index that
542 * occurred between this event and the previous motion event.
543 * Whole numbers are pixels; the value may have a fraction for input devices
544 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700545float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700546 size_t history_index);
547
548/* Get the historical Y coordinate of this event for the given pointer index that
549 * occurred between this event and the previous motion event.
550 * Whole numbers are pixels; the value may have a fraction for input devices
551 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700552float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700553 size_t history_index);
554
555/* Get the historical pressure of this event for the given pointer index that
556 * occurred between this event and the previous motion event.
557 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
558 * however values higher than 1 may be generated depending on the calibration of
559 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700560float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700561 size_t history_index);
562
563/* Get the current scaled value of the approximate size for the given pointer index that
564 * occurred between this event and the previous motion event.
565 * This represents some approximation of the area of the screen being
566 * pressed; the actual value in pixels corresponding to the
567 * touch is normalized with the device specific range of values
568 * and scaled to a value between 0 and 1. The value of size can be used to
569 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700570float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700571 size_t history_index);
572
Jeff Brownc5ed5912010-07-14 18:48:53 -0700573/* Get the historical length of the major axis of an ellipse that describes the touch area
574 * at the point of contact for the given pointer index that
575 * occurred between this event and the previous motion event. */
576float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index,
577 size_t history_index);
578
579/* Get the historical length of the minor axis of an ellipse that describes the touch area
580 * at the point of contact for the given pointer index that
581 * occurred between this event and the previous motion event. */
582float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index,
583 size_t history_index);
584
585/* Get the historical length of the major axis of an ellipse that describes the size
586 * of the approaching tool for the given pointer index that
587 * occurred between this event and the previous motion event.
588 * The tool area represents the estimated size of the finger or pen that is
589 * touching the device independent of its actual touch area at the point of contact. */
590float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index,
591 size_t history_index);
592
593/* Get the historical length of the minor axis of an ellipse that describes the size
594 * of the approaching tool for the given pointer index that
595 * occurred between this event and the previous motion event.
596 * The tool area represents the estimated size of the finger or pen that is
597 * touching the device independent of its actual touch area at the point of contact. */
598float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index,
599 size_t history_index);
600
601/* Get the historical orientation of the touch area and tool area in radians clockwise from
602 * vertical for the given pointer index that
603 * occurred between this event and the previous motion event.
604 * An angle of 0 degrees indicates that the major axis of contact is oriented
605 * upwards, is perfectly circular or is of unknown orientation. A positive angle
606 * indicates that the major axis of contact is oriented to the right. A negative angle
607 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700608 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700609 * (finger pointing fully right). */
610float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
611 size_t history_index);
612
613
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700614/*
615 * Input queue
616 *
617 * An input queue is the facility through which you retrieve input
618 * events.
619 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700620struct AInputQueue;
621typedef struct AInputQueue AInputQueue;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700622
623/*
Dianne Hackborn85448bb2010-07-07 14:27:31 -0700624 * Add this input queue to a looper for processing. See
625 * ALooper_addFd() for information on the callback and data params.
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700626 */
Dianne Hackborn68267412010-07-02 18:52:01 -0700627void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
Dianne Hackborn85448bb2010-07-07 14:27:31 -0700628 ALooper_callbackFunc* callback, void* data);
Dianne Hackborn68267412010-07-02 18:52:01 -0700629
630/*
631 * Remove the input queue from the looper it is currently attached to.
632 */
633void AInputQueue_detachLooper(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700634
635/*
636 * Returns true if there are one or more events available in the
637 * input queue. Returns 1 if the queue has events; 0 if
638 * it does not have events; and a negative value if there is an error.
639 */
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700640int32_t AInputQueue_hasEvents(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700641
642/*
643 * Returns the next available event from the queue. Returns a negative
644 * value if no events are available or an error has occurred.
645 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700646int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700647
648/*
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700649 * Sends the key for standard pre-dispatching -- that is, possibly deliver
650 * it to the current IME to be consumed before the app. Returns 0 if it
651 * was not pre-dispatched, meaning you can process it right now. If non-zero
652 * is returned, you must abandon the current event processing and allow the
653 * event to appear again in the event queue (if it does not get consumed during
654 * pre-dispatching).
655 */
656int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event);
657
658/*
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700659 * Report that dispatching has finished with the given event.
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700660 * This must be called after receiving an event with AInputQueue_get_event().
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700661 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700662void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700663
Jeff Brown6d0fec22010-07-23 21:28:06 -0700664/*
665 * Input devices.
666 *
667 * These functions provide a mechanism for querying the set of available input devices
668 * and their characteristics and capabilities.
669 */
670struct AInputDevice;
671typedef struct AInputDevice AInputDevice;
672
673/*
674 * Populates the supplied array with the ids of all input devices in the system.
675 * Sets nActual to the actual number of devices.
676 * Returns zero if enumeration was successful.
677 * Returns non-zero if the actual number of devices is greater than nMax, in which case the
678 * client should call the method again with a larger id buffer.
679 */
680int32_t AInputDevice_getDeviceIds(int32_t* idBuf, size_t nMax, size_t* nActual);
681
682/*
683 * Acquires a device by id.
684 * Returns NULL if the device was not found.
685 *
686 * Note: The returned object must be freed using AInputDevice_release when no longer needed.
687 */
688AInputDevice* AInputDevice_acquire(int32_t deviceId);
689
690/*
691 * Releases a device previously acquired by AInputDevice_acquire.
692 * If device is NULL, this function does nothing.
693 */
694void AInputDevice_release(AInputDevice* device);
695
696/*
697 * Gets the name of an input device.
698 *
699 * Note: The caller should copy the name into a private buffer since the returned pointer
700 * will become invalid when the device object is released.
701 */
702const char* AInputDevice_getName(AInputDevice* device);
703
704/*
705 * Gets the combination of input sources provided by the input device.
706 */
707uint32_t AInputDevice_getSources(AInputDevice* device);
708
709/*
710 * Gets the keyboard type.
711 */
712int32_t AInputDevice_getKeyboardType(AInputDevice* device);
713
714/* Gets the minimum value, maximum value, flat position and error tolerance for a
715 * particular motion coodinate.
716 * Returns zero if the device supports the specified motion range. */
717int32_t AInputDevice_getMotionRange(AInputDevice* device, int32_t rangeType,
718 float* outMin, float* outMax, float* outFlat, float* outFuzz);
719
720//TODO hasKey, keymap stuff, etc...
721
Jeff Brown46b9ac02010-04-22 18:58:52 -0700722#ifdef __cplusplus
723}
724#endif
725
726#endif // _ANDROID_INPUT_H