blob: 243c33c3a71431ea74cf7e4c309b7049b57bafe8 [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
Kenny Roote30de4e2010-07-28 16:41:02 -070043#include <stdint.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070044#include <sys/types.h>
45#include <android/keycodes.h>
Dianne Hackborn68267412010-07-02 18:52:01 -070046#include <android/looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070047
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/*
Jeff Brown46b9ac02010-04-22 18:58:52 -070053 * Key states (may be returned by queries about the current state of a
54 * particular key code, scan code or switch).
Jeff Brown46b9ac02010-04-22 18:58:52 -070055 */
56enum {
57 /* The key state is unknown or the requested key itself is not supported. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070058 AKEY_STATE_UNKNOWN = -1,
Jeff Brown46b9ac02010-04-22 18:58:52 -070059
60 /* The key is up. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070061 AKEY_STATE_UP = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -070062
63 /* The key is down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070064 AKEY_STATE_DOWN = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -070065
66 /* The key is down but is a virtual key press that is being emulated by the system. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070067 AKEY_STATE_VIRTUAL = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -070068};
69
70/*
71 * Meta key / modifer state.
72 */
73enum {
74 /* No meta keys are pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070075 AMETA_NONE = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -070076
77 /* This mask is used to check whether one of the ALT meta keys is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070078 AMETA_ALT_ON = 0x02,
Jeff Brown46b9ac02010-04-22 18:58:52 -070079
80 /* This mask is used to check whether the left ALT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070081 AMETA_ALT_LEFT_ON = 0x10,
Jeff Brown46b9ac02010-04-22 18:58:52 -070082
83 /* This mask is used to check whether the right ALT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070084 AMETA_ALT_RIGHT_ON = 0x20,
Jeff Brown46b9ac02010-04-22 18:58:52 -070085
86 /* This mask is used to check whether one of the SHIFT meta keys is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070087 AMETA_SHIFT_ON = 0x01,
Jeff Brown46b9ac02010-04-22 18:58:52 -070088
89 /* This mask is used to check whether the left SHIFT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070090 AMETA_SHIFT_LEFT_ON = 0x40,
Jeff Brown46b9ac02010-04-22 18:58:52 -070091
92 /* This mask is used to check whether the right SHIFT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070093 AMETA_SHIFT_RIGHT_ON = 0x80,
Jeff Brown46b9ac02010-04-22 18:58:52 -070094
95 /* This mask is used to check whether the SYM meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070096 AMETA_SYM_ON = 0x04
Jeff Brown46b9ac02010-04-22 18:58:52 -070097};
98
99/*
100 * Input events.
101 *
102 * Input events are opaque structures. Use the provided accessors functions to
103 * read their properties.
104 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700105struct AInputEvent;
106typedef struct AInputEvent AInputEvent;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700107
108/*
109 * Input event types.
110 */
111enum {
112 /* Indicates that the input event is a key event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700113 AINPUT_EVENT_TYPE_KEY = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700114
115 /* Indicates that the input event is a motion event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700116 AINPUT_EVENT_TYPE_MOTION = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -0700117};
118
119/*
120 * Key event actions.
121 */
122enum {
123 /* The key has been pressed down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700124 AKEY_EVENT_ACTION_DOWN = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700125
126 /* The key has been released. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700127 AKEY_EVENT_ACTION_UP = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700128
129 /* Multiple duplicate key events have occurred in a row, or a complex string is
130 * being delivered. The repeat_count property of the key event contains the number
131 * of times the given key code should be executed.
132 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700133 AKEY_EVENT_ACTION_MULTIPLE = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -0700134};
135
136/*
137 * Key event flags.
138 */
139enum {
140 /* This mask is set if the device woke because of this key event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700141 AKEY_EVENT_FLAG_WOKE_HERE = 0x1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700142
143 /* This mask is set if the key event was generated by a software keyboard. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700144 AKEY_EVENT_FLAG_SOFT_KEYBOARD = 0x2,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700145
146 /* 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 -0700147 AKEY_EVENT_FLAG_KEEP_TOUCH_MODE = 0x4,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700148
149 /* This mask is set if an event was known to come from a trusted part
150 * of the system. That is, the event is known to come from the user,
151 * and could not have been spoofed by a third party component. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700152 AKEY_EVENT_FLAG_FROM_SYSTEM = 0x8,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700153
154 /* This mask is used for compatibility, to identify enter keys that are
155 * coming from an IME whose enter key has been auto-labelled "next" or
156 * "done". This allows TextView to dispatch these as normal enter keys
157 * for old applications, but still do the appropriate action when
158 * receiving them. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700159 AKEY_EVENT_FLAG_EDITOR_ACTION = 0x10,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700160
161 /* When associated with up key events, this indicates that the key press
162 * has been canceled. Typically this is used with virtual touch screen
163 * keys, where the user can slide from the virtual key area on to the
164 * display: in that case, the application will receive a canceled up
165 * event and should not perform the action normally associated with the
166 * key. Note that for this to work, the application can not perform an
167 * action for a key until it receives an up or the long press timeout has
168 * expired. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700169 AKEY_EVENT_FLAG_CANCELED = 0x20,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700170
171 /* This key event was generated by a virtual (on-screen) hard key area.
172 * Typically this is an area of the touchscreen, outside of the regular
173 * display, dedicated to "hardware" buttons. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700174 AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY = 0x40,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700175
176 /* This flag is set for the first key repeat that occurs after the
177 * long press timeout. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700178 AKEY_EVENT_FLAG_LONG_PRESS = 0x80,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700179
Jeff Brownc5ed5912010-07-14 18:48:53 -0700180 /* Set when a key event has AKEY_EVENT_FLAG_CANCELED set because a long
Jeff Brown46b9ac02010-04-22 18:58:52 -0700181 * press action was executed while it was down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700182 AKEY_EVENT_FLAG_CANCELED_LONG_PRESS = 0x100,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700183
Jeff Brownc5ed5912010-07-14 18:48:53 -0700184 /* Set for AKEY_EVENT_ACTION_UP when this event's key code is still being
Jeff Brown46b9ac02010-04-22 18:58:52 -0700185 * tracked from its initial down. That is, somebody requested that tracking
186 * started on the key down and a long press has not caused
187 * the tracking to be canceled. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700188 AKEY_EVENT_FLAG_TRACKING = 0x200
Jeff Brown46b9ac02010-04-22 18:58:52 -0700189};
190
191/*
192 * Motion event actions.
193 */
194
195/* Bit shift for the action bits holding the pointer index as
Jeff Brownc5ed5912010-07-14 18:48:53 -0700196 * defined by AMOTION_EVENT_ACTION_POINTER_INDEX_MASK.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700197 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700198#define AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8
Jeff Brown46b9ac02010-04-22 18:58:52 -0700199
200enum {
201 /* Bit mask of the parts of the action code that are the action itself.
202 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700203 AMOTION_EVENT_ACTION_MASK = 0xff,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700204
205 /* Bits in the action code that represent a pointer index, used with
Jeff Brownc5ed5912010-07-14 18:48:53 -0700206 * AMOTION_EVENT_ACTION_POINTER_DOWN and AMOTION_EVENT_ACTION_POINTER_UP. Shifting
207 * down by AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer
Jeff Brown46b9ac02010-04-22 18:58:52 -0700208 * index where the data for the pointer going up or down can be found.
209 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700210 AMOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700211
212 /* A pressed gesture has started, the motion contains the initial starting location.
213 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700214 AMOTION_EVENT_ACTION_DOWN = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700215
216 /* A pressed gesture has finished, the motion contains the final release location
217 * as well as any intermediate points since the last down or move event.
218 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700219 AMOTION_EVENT_ACTION_UP = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700220
Jeff Brownc5ed5912010-07-14 18:48:53 -0700221 /* A change has happened during a press gesture (between AMOTION_EVENT_ACTION_DOWN and
222 * AMOTION_EVENT_ACTION_UP). The motion contains the most recent point, as well as
Jeff Brown46b9ac02010-04-22 18:58:52 -0700223 * any intermediate points since the last down or move event.
224 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700225 AMOTION_EVENT_ACTION_MOVE = 2,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700226
227 /* The current gesture has been aborted.
228 * You will not receive any more points in it. You should treat this as
229 * an up event, but not perform any action that you normally would.
230 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700231 AMOTION_EVENT_ACTION_CANCEL = 3,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700232
233 /* A movement has happened outside of the normal bounds of the UI element.
234 * This does not provide a full gesture, but only the initial location of the movement/touch.
235 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700236 AMOTION_EVENT_ACTION_OUTSIDE = 4,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700237
238 /* A non-primary pointer has gone down.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700239 * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700240 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700241 AMOTION_EVENT_ACTION_POINTER_DOWN = 5,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700242
243 /* A non-primary pointer has gone up.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700244 * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700245 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700246 AMOTION_EVENT_ACTION_POINTER_UP = 6
Jeff Brown46b9ac02010-04-22 18:58:52 -0700247};
248
249/*
250 * Motion event edge touch flags.
251 */
252enum {
253 /* No edges intersected */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700254 AMOTION_EVENT_EDGE_FLAG_NONE = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700255
256 /* Flag indicating the motion event intersected the top edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700257 AMOTION_EVENT_EDGE_FLAG_TOP = 0x01,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700258
259 /* Flag indicating the motion event intersected the bottom edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700260 AMOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700261
262 /* Flag indicating the motion event intersected the left edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700263 AMOTION_EVENT_EDGE_FLAG_LEFT = 0x04,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700264
265 /* Flag indicating the motion event intersected the right edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700266 AMOTION_EVENT_EDGE_FLAG_RIGHT = 0x08
Jeff Brown46b9ac02010-04-22 18:58:52 -0700267};
268
269/*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700270 * Input sources.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700271 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700272 * Refer to the documentation on android.view.InputDevice for more details about input sources
273 * and their correct interpretation.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700274 */
275enum {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700276 AINPUT_SOURCE_CLASS_MASK = 0x000000ff,
277
278 AINPUT_SOURCE_CLASS_BUTTON = 0x00000001,
279 AINPUT_SOURCE_CLASS_POINTER = 0x00000002,
280 AINPUT_SOURCE_CLASS_NAVIGATION = 0x00000004,
281 AINPUT_SOURCE_CLASS_POSITION = 0x00000008,
282 AINPUT_SOURCE_CLASS_JOYSTICK = 0x00000010,
283};
284
285enum {
286 AINPUT_SOURCE_UNKNOWN = 0x00000000,
287
288 AINPUT_SOURCE_KEYBOARD = 0x00000100 | AINPUT_SOURCE_CLASS_BUTTON,
289 AINPUT_SOURCE_DPAD = 0x00000200 | AINPUT_SOURCE_CLASS_BUTTON,
290 AINPUT_SOURCE_GAMEPAD = 0x00000400 | AINPUT_SOURCE_CLASS_BUTTON,
291 AINPUT_SOURCE_TOUCHSCREEN = 0x00001000 | AINPUT_SOURCE_CLASS_POINTER,
292 AINPUT_SOURCE_MOUSE = 0x00002000 | AINPUT_SOURCE_CLASS_POINTER,
293 AINPUT_SOURCE_TRACKBALL = 0x00010000 | AINPUT_SOURCE_CLASS_NAVIGATION,
294 AINPUT_SOURCE_TOUCHPAD = 0x00100000 | AINPUT_SOURCE_CLASS_POSITION,
295 AINPUT_SOURCE_JOYSTICK_LEFT = 0x01000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
296 AINPUT_SOURCE_JOYSTICK_RIGHT = 0x02000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700297};
298
299/*
Jeff Brown6d0fec22010-07-23 21:28:06 -0700300 * Keyboard types.
301 *
302 * Refer to the documentation on android.view.InputDevice for more details.
303 */
304enum {
305 AINPUT_KEYBOARD_TYPE_NONE = 0,
306 AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC = 1,
307 AINPUT_KEYBOARD_TYPE_ALPHABETIC = 2,
308};
309
310/*
311 * Constants used to retrieve information about the range of motion for a particular
312 * coordinate of a motion event.
313 *
314 * Refer to the documentation on android.view.InputDevice for more details about input sources
315 * and their correct interpretation.
316 */
317enum {
318 AINPUT_MOTION_RANGE_X = 0,
319 AINPUT_MOTION_RANGE_Y = 1,
320 AINPUT_MOTION_RANGE_PRESSURE = 2,
321 AINPUT_MOTION_RANGE_SIZE = 3,
322 AINPUT_MOTION_RANGE_TOUCH_MAJOR = 4,
323 AINPUT_MOTION_RANGE_TOUCH_MINOR = 5,
324 AINPUT_MOTION_RANGE_TOOL_MAJOR = 6,
325 AINPUT_MOTION_RANGE_TOOL_MINOR = 7,
326 AINPUT_MOTION_RANGE_ORIENTATION = 8,
327};
328
329
330/*
Jeff Brown46b9ac02010-04-22 18:58:52 -0700331 * Input event accessors.
332 *
333 * Note that most functions can only be used on input events that are of a given type.
334 * Calling these functions on input events of other types will yield undefined behavior.
335 */
336
337/*** Accessors for all input events. ***/
338
339/* Get the input event type. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700340int32_t AInputEvent_getType(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700341
342/* Get the id for the device that an input event came from.
343 *
344 * Input events can be generated by multiple different input devices.
345 * Use the input device id to obtain information about the input
346 * device that was responsible for generating a particular event.
347 *
348 * An input device id of 0 indicates that the event didn't come from a physical device;
349 * other numbers are arbitrary and you shouldn't depend on the values.
350 * Use the provided input device query API to obtain information about input devices.
351 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700352int32_t AInputEvent_getDeviceId(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700353
Jeff Brownc5ed5912010-07-14 18:48:53 -0700354/* Get the input event source. */
355int32_t AInputEvent_getSource(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700356
357/*** Accessors for key events only. ***/
358
359/* Get the key event action. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700360int32_t AKeyEvent_getAction(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700361
362/* Get the key event flags. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700363int32_t AKeyEvent_getFlags(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700364
365/* Get the key code of the key event.
366 * This is the physical key that was pressed, not the Unicode character. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700367int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700368
369/* Get the hardware key id of this key event.
370 * These values are not reliable and vary from device to device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700371int32_t AKeyEvent_getScanCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700372
373/* Get the meta key state. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700374int32_t AKeyEvent_getMetaState(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700375
376/* Get the repeat count of the event.
377 * For both key up an key down events, this is the number of times the key has
378 * repeated with the first down starting at 0 and counting up from there. For
379 * multiple key events, this is the number of down/up pairs that have occurred. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700380int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700381
382/* Get the time of the most recent key down event, in the
383 * java.lang.System.nanoTime() time base. If this is a down event,
384 * this will be the same as eventTime.
385 * Note that when chording keys, this value is the down time of the most recently
386 * pressed key, which may not be the same physical key of this event. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700387int64_t AKeyEvent_getDownTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700388
389/* Get the time this event occurred, in the
390 * java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700391int64_t AKeyEvent_getEventTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700392
393/*** Accessors for motion events only. ***/
394
395/* Get the combined motion event action code and pointer index. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700396int32_t AMotionEvent_getAction(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700397
398/* Get the state of any meta / modifier keys that were in effect when the
399 * event was generated. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700400int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700401
402/* Get a bitfield indicating which edges, if any, were touched by this motion event.
403 * For touch events, clients can use this to determine if the user's finger was
404 * touching the edge of the display. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700405int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700406
407/* Get the time when the user originally pressed down to start a stream of
408 * position events, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700409int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700410
411/* Get the time when this specific event was generated,
412 * in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700413int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700414
Jeff Brown5c225b12010-06-16 01:53:36 -0700415/* Get the X coordinate offset.
416 * For touch events on the screen, this is the delta that was added to the raw
417 * screen coordinates to adjust for the absolute position of the containing windows
418 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700419float AMotionEvent_getXOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700420
421/* Get the precision of the Y coordinates being reported.
422 * For touch events on the screen, this is the delta that was added to the raw
423 * screen coordinates to adjust for the absolute position of the containing windows
424 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700425float AMotionEvent_getYOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700426
Jeff Brown46b9ac02010-04-22 18:58:52 -0700427/* Get the precision of the X coordinates being reported.
428 * You can multiply this number with an X coordinate sample to find the
429 * actual hardware value of the X coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700430float AMotionEvent_getXPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700431
432/* Get the precision of the Y coordinates being reported.
433 * You can multiply this number with a Y coordinate sample to find the
434 * actual hardware value of the Y coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700435float AMotionEvent_getYPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700436
437/* Get the number of pointers of data contained in this event.
438 * Always >= 1. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700439size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700440
441/* Get the pointer identifier associated with a particular pointer
442 * data index is this event. The identifier tells you the actual pointer
443 * number associated with the data, accounting for individual pointers
444 * going up and down since the start of the current gesture. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700445int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700446
Jeff Brown5c225b12010-06-16 01:53:36 -0700447/* Get the original raw X coordinate of this event.
448 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700449 * on the screen, before it had been adjusted for the containing window
450 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700451float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700452
Jeff Brown5c225b12010-06-16 01:53:36 -0700453/* Get the original raw X coordinate of this event.
454 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700455 * on the screen, before it had been adjusted for the containing window
456 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700457float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700458
459/* Get the current X coordinate of this event for the given pointer index.
460 * Whole numbers are pixels; the value may have a fraction for input devices
461 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700462float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700463
464/* Get the current Y coordinate of this event for the given pointer index.
465 * Whole numbers are pixels; the value may have a fraction for input devices
466 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700467float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700468
469/* Get the current pressure of this event for the given pointer index.
470 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
471 * however values higher than 1 may be generated depending on the calibration of
472 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700473float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700474
475/* Get the current scaled value of the approximate size for the given pointer index.
476 * This represents some approximation of the area of the screen being
477 * pressed; the actual value in pixels corresponding to the
478 * touch is normalized with the device specific range of values
479 * and scaled to a value between 0 and 1. The value of size can be used to
480 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700481float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700482
Jeff Brownc5ed5912010-07-14 18:48:53 -0700483/* Get the current length of the major axis of an ellipse that describes the touch area
484 * at the point of contact for the given pointer index. */
485float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index);
486
487/* Get the current length of the minor axis of an ellipse that describes the touch area
488 * at the point of contact for the given pointer index. */
489float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index);
490
491/* Get the current length of the major axis of an ellipse that describes the size
492 * of the approaching tool for the given pointer index.
493 * The tool area represents the estimated size of the finger or pen that is
494 * touching the device independent of its actual touch area at the point of contact. */
495float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index);
496
497/* Get the current length of the minor axis of an ellipse that describes the size
498 * of the approaching tool for the given pointer index.
499 * The tool area represents the estimated size of the finger or pen that is
500 * touching the device independent of its actual touch area at the point of contact. */
501float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index);
502
503/* Get the current orientation of the touch area and tool area in radians clockwise from
504 * vertical for the given pointer index.
505 * An angle of 0 degrees indicates that the major axis of contact is oriented
506 * upwards, is perfectly circular or is of unknown orientation. A positive angle
507 * indicates that the major axis of contact is oriented to the right. A negative angle
508 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700509 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700510 * (finger pointing fully right). */
511float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index);
512
Jeff Brown46b9ac02010-04-22 18:58:52 -0700513/* Get the number of historical points in this event. These are movements that
514 * have occurred between this event and the previous event. This only applies
Jeff Brownc5ed5912010-07-14 18:48:53 -0700515 * to AMOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700516 * Historical samples are indexed from oldest to newest. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700517size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700518
519/* Get the time that a historical movement occurred between this event and
520 * the previous event, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700521int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700522 size_t history_index);
523
Jeff Brown5c225b12010-06-16 01:53:36 -0700524/* Get the historical raw X coordinate of this event for the given pointer index that
525 * occurred between this event and the previous motion event.
526 * For touch events on the screen, this is the original location of the event
527 * on the screen, before it had been adjusted for the containing window
528 * and views.
529 * Whole numbers are pixels; the value may have a fraction for input devices
530 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700531float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700532
533/* Get the historical raw Y coordinate of this event for the given pointer index that
534 * occurred between this event and the previous motion event.
535 * For touch events on the screen, this is the original location of the event
536 * on the screen, before it had been adjusted for the containing window
537 * and views.
538 * Whole numbers are pixels; the value may have a fraction for input devices
539 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700540float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700541
Jeff Brown46b9ac02010-04-22 18:58:52 -0700542/* Get the historical X coordinate of this event for the given pointer index that
543 * occurred between this event and the previous motion event.
544 * Whole numbers are pixels; the value may have a fraction for input devices
545 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700546float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700547 size_t history_index);
548
549/* Get the historical Y coordinate of this event for the given pointer index that
550 * occurred between this event and the previous motion event.
551 * Whole numbers are pixels; the value may have a fraction for input devices
552 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700553float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700554 size_t history_index);
555
556/* Get the historical pressure of this event for the given pointer index that
557 * occurred between this event and the previous motion event.
558 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
559 * however values higher than 1 may be generated depending on the calibration of
560 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700561float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700562 size_t history_index);
563
564/* Get the current scaled value of the approximate size for the given pointer index that
565 * occurred between this event and the previous motion event.
566 * This represents some approximation of the area of the screen being
567 * pressed; the actual value in pixels corresponding to the
568 * touch is normalized with the device specific range of values
569 * and scaled to a value between 0 and 1. The value of size can be used to
570 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700571float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700572 size_t history_index);
573
Jeff Brownc5ed5912010-07-14 18:48:53 -0700574/* Get the historical length of the major axis of an ellipse that describes the touch area
575 * at the point of contact for the given pointer index that
576 * occurred between this event and the previous motion event. */
577float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index,
578 size_t history_index);
579
580/* Get the historical length of the minor axis of an ellipse that describes the touch area
581 * at the point of contact for the given pointer index that
582 * occurred between this event and the previous motion event. */
583float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index,
584 size_t history_index);
585
586/* Get the historical length of the major axis of an ellipse that describes the size
587 * of the approaching tool for the given pointer index that
588 * occurred between this event and the previous motion event.
589 * The tool area represents the estimated size of the finger or pen that is
590 * touching the device independent of its actual touch area at the point of contact. */
591float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index,
592 size_t history_index);
593
594/* Get the historical length of the minor axis of an ellipse that describes the size
595 * of the approaching tool for the given pointer index that
596 * occurred between this event and the previous motion event.
597 * The tool area represents the estimated size of the finger or pen that is
598 * touching the device independent of its actual touch area at the point of contact. */
599float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index,
600 size_t history_index);
601
602/* Get the historical orientation of the touch area and tool area in radians clockwise from
603 * vertical for the given pointer index that
604 * occurred between this event and the previous motion event.
605 * An angle of 0 degrees indicates that the major axis of contact is oriented
606 * upwards, is perfectly circular or is of unknown orientation. A positive angle
607 * indicates that the major axis of contact is oriented to the right. A negative angle
608 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700609 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700610 * (finger pointing fully right). */
611float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
612 size_t history_index);
613
614
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700615/*
616 * Input queue
617 *
618 * An input queue is the facility through which you retrieve input
619 * events.
620 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700621struct AInputQueue;
622typedef struct AInputQueue AInputQueue;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700623
624/*
Dianne Hackborn85448bb2010-07-07 14:27:31 -0700625 * Add this input queue to a looper for processing. See
626 * ALooper_addFd() for information on the callback and data params.
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700627 */
Dianne Hackborn68267412010-07-02 18:52:01 -0700628void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
Dianne Hackborn85448bb2010-07-07 14:27:31 -0700629 ALooper_callbackFunc* callback, void* data);
Dianne Hackborn68267412010-07-02 18:52:01 -0700630
631/*
632 * Remove the input queue from the looper it is currently attached to.
633 */
634void AInputQueue_detachLooper(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700635
636/*
637 * Returns true if there are one or more events available in the
638 * input queue. Returns 1 if the queue has events; 0 if
639 * it does not have events; and a negative value if there is an error.
640 */
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700641int32_t AInputQueue_hasEvents(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700642
643/*
644 * Returns the next available event from the queue. Returns a negative
645 * value if no events are available or an error has occurred.
646 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700647int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700648
649/*
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700650 * Sends the key for standard pre-dispatching -- that is, possibly deliver
651 * it to the current IME to be consumed before the app. Returns 0 if it
652 * was not pre-dispatched, meaning you can process it right now. If non-zero
653 * is returned, you must abandon the current event processing and allow the
654 * event to appear again in the event queue (if it does not get consumed during
655 * pre-dispatching).
656 */
657int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event);
658
659/*
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700660 * Report that dispatching has finished with the given event.
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700661 * This must be called after receiving an event with AInputQueue_get_event().
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700662 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700663void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700664
Jeff Brown6d0fec22010-07-23 21:28:06 -0700665/*
666 * Input devices.
667 *
668 * These functions provide a mechanism for querying the set of available input devices
669 * and their characteristics and capabilities.
670 */
671struct AInputDevice;
672typedef struct AInputDevice AInputDevice;
673
674/*
675 * Populates the supplied array with the ids of all input devices in the system.
676 * Sets nActual to the actual number of devices.
677 * Returns zero if enumeration was successful.
678 * Returns non-zero if the actual number of devices is greater than nMax, in which case the
679 * client should call the method again with a larger id buffer.
680 */
681int32_t AInputDevice_getDeviceIds(int32_t* idBuf, size_t nMax, size_t* nActual);
682
683/*
684 * Acquires a device by id.
685 * Returns NULL if the device was not found.
686 *
687 * Note: The returned object must be freed using AInputDevice_release when no longer needed.
688 */
689AInputDevice* AInputDevice_acquire(int32_t deviceId);
690
691/*
692 * Releases a device previously acquired by AInputDevice_acquire.
693 * If device is NULL, this function does nothing.
694 */
695void AInputDevice_release(AInputDevice* device);
696
697/*
698 * Gets the name of an input device.
699 *
700 * Note: The caller should copy the name into a private buffer since the returned pointer
701 * will become invalid when the device object is released.
702 */
703const char* AInputDevice_getName(AInputDevice* device);
704
705/*
706 * Gets the combination of input sources provided by the input device.
707 */
708uint32_t AInputDevice_getSources(AInputDevice* device);
709
710/*
711 * Gets the keyboard type.
712 */
713int32_t AInputDevice_getKeyboardType(AInputDevice* device);
714
715/* Gets the minimum value, maximum value, flat position and error tolerance for a
716 * particular motion coodinate.
717 * Returns zero if the device supports the specified motion range. */
718int32_t AInputDevice_getMotionRange(AInputDevice* device, int32_t rangeType,
719 float* outMin, float* outMax, float* outFlat, float* outFuzz);
720
721//TODO hasKey, keymap stuff, etc...
722
Jeff Brown46b9ac02010-04-22 18:58:52 -0700723#ifdef __cplusplus
724}
725#endif
726
727#endif // _ANDROID_INPUT_H