blob: c1134bf8c7bcc517aaf2a96763c23b385c7dd7d8 [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/*
Jeff Brown85a31762010-09-01 17:01:00 -0700250 * Motion event flags.
251 */
252enum {
253 /* This flag indicates that the window that received this motion event is partly
254 * or wholly obscured by another visible window above it. This flag is set to true
255 * even if the event did not directly pass through the obscured area.
256 * A security sensitive application can check this flag to identify situations in which
257 * a malicious application may have covered up part of its content for the purpose
258 * of misleading the user or hijacking touches. An appropriate response might be
259 * to drop the suspect touches or to take additional precautions to confirm the user's
260 * actual intent.
261 */
262 AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED = 0x1,
263};
264
265/*
Jeff Brown46b9ac02010-04-22 18:58:52 -0700266 * Motion event edge touch flags.
267 */
268enum {
269 /* No edges intersected */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700270 AMOTION_EVENT_EDGE_FLAG_NONE = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700271
272 /* Flag indicating the motion event intersected the top edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700273 AMOTION_EVENT_EDGE_FLAG_TOP = 0x01,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700274
275 /* Flag indicating the motion event intersected the bottom edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700276 AMOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700277
278 /* Flag indicating the motion event intersected the left edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700279 AMOTION_EVENT_EDGE_FLAG_LEFT = 0x04,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700280
281 /* Flag indicating the motion event intersected the right edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700282 AMOTION_EVENT_EDGE_FLAG_RIGHT = 0x08
Jeff Brown46b9ac02010-04-22 18:58:52 -0700283};
284
285/*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700286 * Input sources.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700287 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700288 * Refer to the documentation on android.view.InputDevice for more details about input sources
289 * and their correct interpretation.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700290 */
291enum {
Jeff Brownc5ed5912010-07-14 18:48:53 -0700292 AINPUT_SOURCE_CLASS_MASK = 0x000000ff,
293
294 AINPUT_SOURCE_CLASS_BUTTON = 0x00000001,
295 AINPUT_SOURCE_CLASS_POINTER = 0x00000002,
296 AINPUT_SOURCE_CLASS_NAVIGATION = 0x00000004,
297 AINPUT_SOURCE_CLASS_POSITION = 0x00000008,
298 AINPUT_SOURCE_CLASS_JOYSTICK = 0x00000010,
299};
300
301enum {
302 AINPUT_SOURCE_UNKNOWN = 0x00000000,
303
304 AINPUT_SOURCE_KEYBOARD = 0x00000100 | AINPUT_SOURCE_CLASS_BUTTON,
305 AINPUT_SOURCE_DPAD = 0x00000200 | AINPUT_SOURCE_CLASS_BUTTON,
306 AINPUT_SOURCE_GAMEPAD = 0x00000400 | AINPUT_SOURCE_CLASS_BUTTON,
307 AINPUT_SOURCE_TOUCHSCREEN = 0x00001000 | AINPUT_SOURCE_CLASS_POINTER,
308 AINPUT_SOURCE_MOUSE = 0x00002000 | AINPUT_SOURCE_CLASS_POINTER,
309 AINPUT_SOURCE_TRACKBALL = 0x00010000 | AINPUT_SOURCE_CLASS_NAVIGATION,
310 AINPUT_SOURCE_TOUCHPAD = 0x00100000 | AINPUT_SOURCE_CLASS_POSITION,
311 AINPUT_SOURCE_JOYSTICK_LEFT = 0x01000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
312 AINPUT_SOURCE_JOYSTICK_RIGHT = 0x02000000 | AINPUT_SOURCE_CLASS_JOYSTICK,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700313};
314
315/*
Jeff Brown6d0fec22010-07-23 21:28:06 -0700316 * Keyboard types.
317 *
318 * Refer to the documentation on android.view.InputDevice for more details.
319 */
320enum {
321 AINPUT_KEYBOARD_TYPE_NONE = 0,
322 AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC = 1,
323 AINPUT_KEYBOARD_TYPE_ALPHABETIC = 2,
324};
325
326/*
327 * Constants used to retrieve information about the range of motion for a particular
328 * coordinate of a motion event.
329 *
330 * Refer to the documentation on android.view.InputDevice for more details about input sources
331 * and their correct interpretation.
332 */
333enum {
334 AINPUT_MOTION_RANGE_X = 0,
335 AINPUT_MOTION_RANGE_Y = 1,
336 AINPUT_MOTION_RANGE_PRESSURE = 2,
337 AINPUT_MOTION_RANGE_SIZE = 3,
338 AINPUT_MOTION_RANGE_TOUCH_MAJOR = 4,
339 AINPUT_MOTION_RANGE_TOUCH_MINOR = 5,
340 AINPUT_MOTION_RANGE_TOOL_MAJOR = 6,
341 AINPUT_MOTION_RANGE_TOOL_MINOR = 7,
342 AINPUT_MOTION_RANGE_ORIENTATION = 8,
343};
344
345
346/*
Jeff Brown46b9ac02010-04-22 18:58:52 -0700347 * Input event accessors.
348 *
349 * Note that most functions can only be used on input events that are of a given type.
350 * Calling these functions on input events of other types will yield undefined behavior.
351 */
352
353/*** Accessors for all input events. ***/
354
355/* Get the input event type. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700356int32_t AInputEvent_getType(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700357
358/* Get the id for the device that an input event came from.
359 *
360 * Input events can be generated by multiple different input devices.
361 * Use the input device id to obtain information about the input
362 * device that was responsible for generating a particular event.
363 *
364 * An input device id of 0 indicates that the event didn't come from a physical device;
365 * other numbers are arbitrary and you shouldn't depend on the values.
366 * Use the provided input device query API to obtain information about input devices.
367 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700368int32_t AInputEvent_getDeviceId(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700369
Jeff Brownc5ed5912010-07-14 18:48:53 -0700370/* Get the input event source. */
371int32_t AInputEvent_getSource(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700372
373/*** Accessors for key events only. ***/
374
375/* Get the key event action. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700376int32_t AKeyEvent_getAction(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700377
378/* Get the key event flags. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700379int32_t AKeyEvent_getFlags(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700380
381/* Get the key code of the key event.
382 * This is the physical key that was pressed, not the Unicode character. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700383int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700384
385/* Get the hardware key id of this key event.
386 * These values are not reliable and vary from device to device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700387int32_t AKeyEvent_getScanCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700388
389/* Get the meta key state. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700390int32_t AKeyEvent_getMetaState(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700391
392/* Get the repeat count of the event.
393 * For both key up an key down events, this is the number of times the key has
394 * repeated with the first down starting at 0 and counting up from there. For
395 * multiple key events, this is the number of down/up pairs that have occurred. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700396int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700397
398/* Get the time of the most recent key down event, in the
399 * java.lang.System.nanoTime() time base. If this is a down event,
400 * this will be the same as eventTime.
401 * Note that when chording keys, this value is the down time of the most recently
402 * pressed key, which may not be the same physical key of this event. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700403int64_t AKeyEvent_getDownTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700404
405/* Get the time this event occurred, in the
406 * java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700407int64_t AKeyEvent_getEventTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700408
409/*** Accessors for motion events only. ***/
410
411/* Get the combined motion event action code and pointer index. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700412int32_t AMotionEvent_getAction(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700413
Jeff Brown85a31762010-09-01 17:01:00 -0700414/* Get the motion event flags. */
415int32_t AMotionEvent_getFlags(const AInputEvent* motion_event);
416
Jeff Brown46b9ac02010-04-22 18:58:52 -0700417/* Get the state of any meta / modifier keys that were in effect when the
418 * event was generated. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700419int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700420
421/* Get a bitfield indicating which edges, if any, were touched by this motion event.
422 * For touch events, clients can use this to determine if the user's finger was
423 * touching the edge of the display. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700424int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700425
426/* Get the time when the user originally pressed down to start a stream of
427 * position events, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700428int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700429
430/* Get the time when this specific event was generated,
431 * in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700432int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700433
Jeff Brown5c225b12010-06-16 01:53:36 -0700434/* Get the X coordinate offset.
435 * For touch events on the screen, this is the delta that was added to the raw
436 * screen coordinates to adjust for the absolute position of the containing windows
437 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700438float AMotionEvent_getXOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700439
440/* Get the precision of the Y coordinates being reported.
441 * For touch events on the screen, this is the delta that was added to the raw
442 * screen coordinates to adjust for the absolute position of the containing windows
443 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700444float AMotionEvent_getYOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700445
Jeff Brown46b9ac02010-04-22 18:58:52 -0700446/* Get the precision of the X coordinates being reported.
447 * You can multiply this number with an X coordinate sample to find the
448 * actual hardware value of the X coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700449float AMotionEvent_getXPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700450
451/* Get the precision of the Y coordinates being reported.
452 * You can multiply this number with a Y coordinate sample to find the
453 * actual hardware value of the Y coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700454float AMotionEvent_getYPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700455
456/* Get the number of pointers of data contained in this event.
457 * Always >= 1. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700458size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700459
460/* Get the pointer identifier associated with a particular pointer
461 * data index is this event. The identifier tells you the actual pointer
462 * number associated with the data, accounting for individual pointers
463 * going up and down since the start of the current gesture. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700464int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700465
Jeff Brown5c225b12010-06-16 01:53:36 -0700466/* Get the original raw X coordinate of this event.
467 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700468 * on the screen, before it had been adjusted for the containing window
469 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700470float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700471
Jeff Brown5c225b12010-06-16 01:53:36 -0700472/* Get the original raw X coordinate of this event.
473 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700474 * on the screen, before it had been adjusted for the containing window
475 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700476float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700477
478/* Get the current X coordinate of this event for the given pointer index.
479 * Whole numbers are pixels; the value may have a fraction for input devices
480 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700481float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700482
483/* Get the current Y coordinate of this event for the given pointer index.
484 * Whole numbers are pixels; the value may have a fraction for input devices
485 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700486float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700487
488/* Get the current pressure of this event for the given pointer index.
489 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
490 * however values higher than 1 may be generated depending on the calibration of
491 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700492float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700493
494/* Get the current scaled value of the approximate size for the given pointer index.
495 * This represents some approximation of the area of the screen being
496 * pressed; the actual value in pixels corresponding to the
497 * touch is normalized with the device specific range of values
498 * and scaled to a value between 0 and 1. The value of size can be used to
499 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700500float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700501
Jeff Brownc5ed5912010-07-14 18:48:53 -0700502/* Get the current length of the major axis of an ellipse that describes the touch area
503 * at the point of contact for the given pointer index. */
504float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index);
505
506/* Get the current length of the minor axis of an ellipse that describes the touch area
507 * at the point of contact for the given pointer index. */
508float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index);
509
510/* Get the current length of the major axis of an ellipse that describes the size
511 * of the approaching tool for the given pointer index.
512 * The tool area represents the estimated size of the finger or pen that is
513 * touching the device independent of its actual touch area at the point of contact. */
514float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index);
515
516/* Get the current length of the minor axis of an ellipse that describes the size
517 * of the approaching tool for the given pointer index.
518 * The tool area represents the estimated size of the finger or pen that is
519 * touching the device independent of its actual touch area at the point of contact. */
520float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index);
521
522/* Get the current orientation of the touch area and tool area in radians clockwise from
523 * vertical for the given pointer index.
524 * An angle of 0 degrees indicates that the major axis of contact is oriented
525 * upwards, is perfectly circular or is of unknown orientation. A positive angle
526 * indicates that the major axis of contact is oriented to the right. A negative angle
527 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700528 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700529 * (finger pointing fully right). */
530float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index);
531
Jeff Brown46b9ac02010-04-22 18:58:52 -0700532/* Get the number of historical points in this event. These are movements that
533 * have occurred between this event and the previous event. This only applies
Jeff Brownc5ed5912010-07-14 18:48:53 -0700534 * to AMOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700535 * Historical samples are indexed from oldest to newest. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700536size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700537
538/* Get the time that a historical movement occurred between this event and
539 * the previous event, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700540int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700541 size_t history_index);
542
Jeff Brown5c225b12010-06-16 01:53:36 -0700543/* Get the historical raw X coordinate of this event for the given pointer index that
544 * occurred between this event and the previous motion event.
545 * For touch events on the screen, this is the original location of the event
546 * on the screen, before it had been adjusted for the containing window
547 * and views.
548 * Whole numbers are pixels; the value may have a fraction for input devices
549 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700550float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700551
552/* Get the historical raw Y coordinate of this event for the given pointer index that
553 * occurred between this event and the previous motion event.
554 * For touch events on the screen, this is the original location of the event
555 * on the screen, before it had been adjusted for the containing window
556 * and views.
557 * Whole numbers are pixels; the value may have a fraction for input devices
558 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700559float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700560
Jeff Brown46b9ac02010-04-22 18:58:52 -0700561/* Get the historical X coordinate of this event for the given pointer index that
562 * occurred between this event and the previous motion event.
563 * Whole numbers are pixels; the value may have a fraction for input devices
564 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700565float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700566 size_t history_index);
567
568/* Get the historical Y coordinate of this event for the given pointer index that
569 * occurred between this event and the previous motion event.
570 * Whole numbers are pixels; the value may have a fraction for input devices
571 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700572float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700573 size_t history_index);
574
575/* Get the historical pressure of this event for the given pointer index that
576 * occurred between this event and the previous motion event.
577 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
578 * however values higher than 1 may be generated depending on the calibration of
579 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700580float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700581 size_t history_index);
582
583/* Get the current scaled value of the approximate size for the given pointer index that
584 * occurred between this event and the previous motion event.
585 * This represents some approximation of the area of the screen being
586 * pressed; the actual value in pixels corresponding to the
587 * touch is normalized with the device specific range of values
588 * and scaled to a value between 0 and 1. The value of size can be used to
589 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700590float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700591 size_t history_index);
592
Jeff Brownc5ed5912010-07-14 18:48:53 -0700593/* Get the historical length of the major axis of an ellipse that describes the touch area
594 * at the point of contact for the given pointer index that
595 * occurred between this event and the previous motion event. */
596float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index,
597 size_t history_index);
598
599/* Get the historical length of the minor axis of an ellipse that describes the touch area
600 * at the point of contact for the given pointer index that
601 * occurred between this event and the previous motion event. */
602float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index,
603 size_t history_index);
604
605/* Get the historical length of the major axis of an ellipse that describes the size
606 * of the approaching tool for the given pointer index that
607 * occurred between this event and the previous motion event.
608 * The tool area represents the estimated size of the finger or pen that is
609 * touching the device independent of its actual touch area at the point of contact. */
610float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index,
611 size_t history_index);
612
613/* Get the historical length of the minor axis of an ellipse that describes the size
614 * of the approaching tool for the given pointer index that
615 * occurred between this event and the previous motion event.
616 * The tool area represents the estimated size of the finger or pen that is
617 * touching the device independent of its actual touch area at the point of contact. */
618float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index,
619 size_t history_index);
620
621/* Get the historical orientation of the touch area and tool area in radians clockwise from
622 * vertical for the given pointer index that
623 * occurred between this event and the previous motion event.
624 * An angle of 0 degrees indicates that the major axis of contact is oriented
625 * upwards, is perfectly circular or is of unknown orientation. A positive angle
626 * indicates that the major axis of contact is oriented to the right. A negative angle
627 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700628 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700629 * (finger pointing fully right). */
630float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
631 size_t history_index);
632
633
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700634/*
635 * Input queue
636 *
637 * An input queue is the facility through which you retrieve input
638 * events.
639 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700640struct AInputQueue;
641typedef struct AInputQueue AInputQueue;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700642
643/*
Dianne Hackborn85448bb2010-07-07 14:27:31 -0700644 * Add this input queue to a looper for processing. See
Dianne Hackborn42c03e52010-09-07 15:28:30 -0700645 * ALooper_addFd() for information on the ident, callback, and data params.
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700646 */
Dianne Hackborn68267412010-07-02 18:52:01 -0700647void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
Jeff Brown4fe6c3e2010-09-13 23:17:30 -0700648 int ident, ALooper_callbackFunc callback, void* data);
Dianne Hackborn68267412010-07-02 18:52:01 -0700649
650/*
651 * Remove the input queue from the looper it is currently attached to.
652 */
653void AInputQueue_detachLooper(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700654
655/*
656 * Returns true if there are one or more events available in the
657 * input queue. Returns 1 if the queue has events; 0 if
658 * it does not have events; and a negative value if there is an error.
659 */
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700660int32_t AInputQueue_hasEvents(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700661
662/*
663 * Returns the next available event from the queue. Returns a negative
664 * value if no events are available or an error has occurred.
665 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700666int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700667
668/*
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700669 * Sends the key for standard pre-dispatching -- that is, possibly deliver
670 * it to the current IME to be consumed before the app. Returns 0 if it
671 * was not pre-dispatched, meaning you can process it right now. If non-zero
672 * is returned, you must abandon the current event processing and allow the
673 * event to appear again in the event queue (if it does not get consumed during
674 * pre-dispatching).
675 */
676int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event);
677
678/*
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700679 * Report that dispatching has finished with the given event.
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700680 * This must be called after receiving an event with AInputQueue_get_event().
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700681 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700682void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700683
Jeff Brown46b9ac02010-04-22 18:58:52 -0700684#ifdef __cplusplus
685}
686#endif
687
688#endif // _ANDROID_INPUT_H