blob: 7df13c34b1b1e37093c9c5ecbd565254a24e5e20 [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,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700298};
299
300enum {
301 AINPUT_SOURCE_UNKNOWN = 0x00000000,
302
303 AINPUT_SOURCE_KEYBOARD = 0x00000100 | AINPUT_SOURCE_CLASS_BUTTON,
304 AINPUT_SOURCE_DPAD = 0x00000200 | AINPUT_SOURCE_CLASS_BUTTON,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700305 AINPUT_SOURCE_TOUCHSCREEN = 0x00001000 | AINPUT_SOURCE_CLASS_POINTER,
306 AINPUT_SOURCE_MOUSE = 0x00002000 | AINPUT_SOURCE_CLASS_POINTER,
307 AINPUT_SOURCE_TRACKBALL = 0x00010000 | AINPUT_SOURCE_CLASS_NAVIGATION,
308 AINPUT_SOURCE_TOUCHPAD = 0x00100000 | AINPUT_SOURCE_CLASS_POSITION,
Jeff Brownc3db8582010-10-20 15:33:38 -0700309
310 AINPUT_SOURCE_ANY = 0xffffff00,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700311};
312
313/*
Jeff Brown6d0fec22010-07-23 21:28:06 -0700314 * Keyboard types.
315 *
316 * Refer to the documentation on android.view.InputDevice for more details.
317 */
318enum {
319 AINPUT_KEYBOARD_TYPE_NONE = 0,
320 AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC = 1,
321 AINPUT_KEYBOARD_TYPE_ALPHABETIC = 2,
322};
323
324/*
325 * Constants used to retrieve information about the range of motion for a particular
326 * coordinate of a motion event.
327 *
328 * Refer to the documentation on android.view.InputDevice for more details about input sources
329 * and their correct interpretation.
330 */
331enum {
332 AINPUT_MOTION_RANGE_X = 0,
333 AINPUT_MOTION_RANGE_Y = 1,
334 AINPUT_MOTION_RANGE_PRESSURE = 2,
335 AINPUT_MOTION_RANGE_SIZE = 3,
336 AINPUT_MOTION_RANGE_TOUCH_MAJOR = 4,
337 AINPUT_MOTION_RANGE_TOUCH_MINOR = 5,
338 AINPUT_MOTION_RANGE_TOOL_MAJOR = 6,
339 AINPUT_MOTION_RANGE_TOOL_MINOR = 7,
340 AINPUT_MOTION_RANGE_ORIENTATION = 8,
341};
342
343
344/*
Jeff Brown46b9ac02010-04-22 18:58:52 -0700345 * Input event accessors.
346 *
347 * Note that most functions can only be used on input events that are of a given type.
348 * Calling these functions on input events of other types will yield undefined behavior.
349 */
350
351/*** Accessors for all input events. ***/
352
353/* Get the input event type. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700354int32_t AInputEvent_getType(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700355
356/* Get the id for the device that an input event came from.
357 *
358 * Input events can be generated by multiple different input devices.
359 * Use the input device id to obtain information about the input
360 * device that was responsible for generating a particular event.
361 *
362 * An input device id of 0 indicates that the event didn't come from a physical device;
363 * other numbers are arbitrary and you shouldn't depend on the values.
364 * Use the provided input device query API to obtain information about input devices.
365 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700366int32_t AInputEvent_getDeviceId(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700367
Jeff Brownc5ed5912010-07-14 18:48:53 -0700368/* Get the input event source. */
369int32_t AInputEvent_getSource(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700370
371/*** Accessors for key events only. ***/
372
373/* Get the key event action. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700374int32_t AKeyEvent_getAction(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700375
376/* Get the key event flags. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700377int32_t AKeyEvent_getFlags(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700378
379/* Get the key code of the key event.
380 * This is the physical key that was pressed, not the Unicode character. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700381int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700382
383/* Get the hardware key id of this key event.
384 * These values are not reliable and vary from device to device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700385int32_t AKeyEvent_getScanCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700386
387/* Get the meta key state. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700388int32_t AKeyEvent_getMetaState(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700389
390/* Get the repeat count of the event.
391 * For both key up an key down events, this is the number of times the key has
392 * repeated with the first down starting at 0 and counting up from there. For
393 * multiple key events, this is the number of down/up pairs that have occurred. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700394int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700395
396/* Get the time of the most recent key down event, in the
397 * java.lang.System.nanoTime() time base. If this is a down event,
398 * this will be the same as eventTime.
399 * Note that when chording keys, this value is the down time of the most recently
400 * pressed key, which may not be the same physical key of this event. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700401int64_t AKeyEvent_getDownTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700402
403/* Get the time this event occurred, in the
404 * java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700405int64_t AKeyEvent_getEventTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700406
407/*** Accessors for motion events only. ***/
408
409/* Get the combined motion event action code and pointer index. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700410int32_t AMotionEvent_getAction(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700411
Jeff Brown85a31762010-09-01 17:01:00 -0700412/* Get the motion event flags. */
413int32_t AMotionEvent_getFlags(const AInputEvent* motion_event);
414
Jeff Brown46b9ac02010-04-22 18:58:52 -0700415/* Get the state of any meta / modifier keys that were in effect when the
416 * event was generated. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700417int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700418
419/* Get a bitfield indicating which edges, if any, were touched by this motion event.
420 * For touch events, clients can use this to determine if the user's finger was
421 * touching the edge of the display. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700422int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700423
424/* Get the time when the user originally pressed down to start a stream of
425 * position events, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700426int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700427
428/* Get the time when this specific event was generated,
429 * in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700430int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700431
Jeff Brown5c225b12010-06-16 01:53:36 -0700432/* Get the X coordinate offset.
433 * For touch events on the screen, this is the delta that was added to the raw
434 * screen coordinates to adjust for the absolute position of the containing windows
435 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700436float AMotionEvent_getXOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700437
438/* Get the precision of the Y coordinates being reported.
439 * For touch events on the screen, this is the delta that was added to the raw
440 * screen coordinates to adjust for the absolute position of the containing windows
441 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700442float AMotionEvent_getYOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700443
Jeff Brown46b9ac02010-04-22 18:58:52 -0700444/* Get the precision of the X coordinates being reported.
445 * You can multiply this number with an X coordinate sample to find the
446 * actual hardware value of the X coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700447float AMotionEvent_getXPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700448
449/* Get the precision of the Y coordinates being reported.
450 * You can multiply this number with a Y coordinate sample to find the
451 * actual hardware value of the Y coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700452float AMotionEvent_getYPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700453
454/* Get the number of pointers of data contained in this event.
455 * Always >= 1. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700456size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700457
458/* Get the pointer identifier associated with a particular pointer
459 * data index is this event. The identifier tells you the actual pointer
460 * number associated with the data, accounting for individual pointers
461 * going up and down since the start of the current gesture. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700462int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700463
Jeff Brown5c225b12010-06-16 01:53:36 -0700464/* Get the original raw X coordinate of this event.
465 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700466 * on the screen, before it had been adjusted for the containing window
467 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700468float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700469
Jeff Brown5c225b12010-06-16 01:53:36 -0700470/* Get the original raw X coordinate of this event.
471 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700472 * on the screen, before it had been adjusted for the containing window
473 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700474float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700475
476/* Get the current X coordinate of this event for the given pointer index.
477 * Whole numbers are pixels; the value may have a fraction for input devices
478 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700479float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700480
481/* Get the current Y coordinate of this event for the given pointer index.
482 * Whole numbers are pixels; the value may have a fraction for input devices
483 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700484float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700485
486/* Get the current pressure of this event for the given pointer index.
487 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
488 * however values higher than 1 may be generated depending on the calibration of
489 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700490float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700491
492/* Get the current scaled value of the approximate size for the given pointer index.
493 * This represents some approximation of the area of the screen being
494 * pressed; the actual value in pixels corresponding to the
495 * touch is normalized with the device specific range of values
496 * and scaled to a value between 0 and 1. The value of size can be used to
497 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700498float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700499
Jeff Brownc5ed5912010-07-14 18:48:53 -0700500/* Get the current length of the major axis of an ellipse that describes the touch area
501 * at the point of contact for the given pointer index. */
502float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index);
503
504/* Get the current length of the minor axis of an ellipse that describes the touch area
505 * at the point of contact for the given pointer index. */
506float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index);
507
508/* Get the current length of the major axis of an ellipse that describes the size
509 * of the approaching tool for the given pointer index.
510 * The tool area represents the estimated size of the finger or pen that is
511 * touching the device independent of its actual touch area at the point of contact. */
512float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index);
513
514/* Get the current length of the minor axis of an ellipse that describes the size
515 * of the approaching tool for the given pointer index.
516 * The tool area represents the estimated size of the finger or pen that is
517 * touching the device independent of its actual touch area at the point of contact. */
518float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index);
519
520/* Get the current orientation of the touch area and tool area in radians clockwise from
521 * vertical for the given pointer index.
522 * An angle of 0 degrees indicates that the major axis of contact is oriented
523 * upwards, is perfectly circular or is of unknown orientation. A positive angle
524 * indicates that the major axis of contact is oriented to the right. A negative angle
525 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700526 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700527 * (finger pointing fully right). */
528float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index);
529
Jeff Brown46b9ac02010-04-22 18:58:52 -0700530/* Get the number of historical points in this event. These are movements that
531 * have occurred between this event and the previous event. This only applies
Jeff Brownc5ed5912010-07-14 18:48:53 -0700532 * to AMOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700533 * Historical samples are indexed from oldest to newest. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700534size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700535
536/* Get the time that a historical movement occurred between this event and
537 * the previous event, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700538int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700539 size_t history_index);
540
Jeff Brown5c225b12010-06-16 01:53:36 -0700541/* Get the historical raw X coordinate of this event for the given pointer index that
542 * occurred between this event and the previous motion event.
543 * For touch events on the screen, this is the original location of the event
544 * on the screen, before it had been adjusted for the containing window
545 * and views.
546 * Whole numbers are pixels; the value may have a fraction for input devices
547 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700548float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700549
550/* Get the historical raw Y coordinate of this event for the given pointer index that
551 * occurred between this event and the previous motion event.
552 * For touch events on the screen, this is the original location of the event
553 * on the screen, before it had been adjusted for the containing window
554 * and views.
555 * Whole numbers are pixels; the value may have a fraction for input devices
556 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700557float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700558
Jeff Brown46b9ac02010-04-22 18:58:52 -0700559/* Get the historical X coordinate of this event for the given pointer index that
560 * occurred between this event and the previous motion event.
561 * Whole numbers are pixels; the value may have a fraction for input devices
562 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700563float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700564 size_t history_index);
565
566/* Get the historical Y coordinate of this event for the given pointer index that
567 * occurred between this event and the previous motion event.
568 * Whole numbers are pixels; the value may have a fraction for input devices
569 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700570float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700571 size_t history_index);
572
573/* Get the historical pressure of this event for the given pointer index that
574 * occurred between this event and the previous motion event.
575 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
576 * however values higher than 1 may be generated depending on the calibration of
577 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700578float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700579 size_t history_index);
580
581/* Get the current scaled value of the approximate size for the given pointer index that
582 * occurred between this event and the previous motion event.
583 * This represents some approximation of the area of the screen being
584 * pressed; the actual value in pixels corresponding to the
585 * touch is normalized with the device specific range of values
586 * and scaled to a value between 0 and 1. The value of size can be used to
587 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700588float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700589 size_t history_index);
590
Jeff Brownc5ed5912010-07-14 18:48:53 -0700591/* Get the historical length of the major axis of an ellipse that describes the touch area
592 * at the point of contact for the given pointer index that
593 * occurred between this event and the previous motion event. */
594float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index,
595 size_t history_index);
596
597/* Get the historical length of the minor axis of an ellipse that describes the touch area
598 * at the point of contact for the given pointer index that
599 * occurred between this event and the previous motion event. */
600float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index,
601 size_t history_index);
602
603/* Get the historical length of the major axis of an ellipse that describes the size
604 * of the approaching tool for the given pointer index that
605 * occurred between this event and the previous motion event.
606 * The tool area represents the estimated size of the finger or pen that is
607 * touching the device independent of its actual touch area at the point of contact. */
608float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index,
609 size_t history_index);
610
611/* Get the historical length of the minor axis of an ellipse that describes the size
612 * of the approaching tool for the given pointer index that
613 * occurred between this event and the previous motion event.
614 * The tool area represents the estimated size of the finger or pen that is
615 * touching the device independent of its actual touch area at the point of contact. */
616float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index,
617 size_t history_index);
618
619/* Get the historical orientation of the touch area and tool area in radians clockwise from
620 * vertical for the given pointer index that
621 * occurred between this event and the previous motion event.
622 * An angle of 0 degrees indicates that the major axis of contact is oriented
623 * upwards, is perfectly circular or is of unknown orientation. A positive angle
624 * indicates that the major axis of contact is oriented to the right. A negative angle
625 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700626 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700627 * (finger pointing fully right). */
628float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
629 size_t history_index);
630
631
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700632/*
633 * Input queue
634 *
635 * An input queue is the facility through which you retrieve input
636 * events.
637 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700638struct AInputQueue;
639typedef struct AInputQueue AInputQueue;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700640
641/*
Dianne Hackborn85448bb2010-07-07 14:27:31 -0700642 * Add this input queue to a looper for processing. See
Dianne Hackborn42c03e52010-09-07 15:28:30 -0700643 * ALooper_addFd() for information on the ident, callback, and data params.
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700644 */
Dianne Hackborn68267412010-07-02 18:52:01 -0700645void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
Jeff Brown4fe6c3e2010-09-13 23:17:30 -0700646 int ident, ALooper_callbackFunc callback, void* data);
Dianne Hackborn68267412010-07-02 18:52:01 -0700647
648/*
649 * Remove the input queue from the looper it is currently attached to.
650 */
651void AInputQueue_detachLooper(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700652
653/*
654 * Returns true if there are one or more events available in the
655 * input queue. Returns 1 if the queue has events; 0 if
656 * it does not have events; and a negative value if there is an error.
657 */
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700658int32_t AInputQueue_hasEvents(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700659
660/*
661 * Returns the next available event from the queue. Returns a negative
662 * value if no events are available or an error has occurred.
663 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700664int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700665
666/*
Dianne Hackborn2c6081c2010-07-15 17:44:53 -0700667 * Sends the key for standard pre-dispatching -- that is, possibly deliver
668 * it to the current IME to be consumed before the app. Returns 0 if it
669 * was not pre-dispatched, meaning you can process it right now. If non-zero
670 * is returned, you must abandon the current event processing and allow the
671 * event to appear again in the event queue (if it does not get consumed during
672 * pre-dispatching).
673 */
674int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event);
675
676/*
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700677 * Report that dispatching has finished with the given event.
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700678 * This must be called after receiving an event with AInputQueue_get_event().
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700679 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700680void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700681
Jeff Brown46b9ac02010-04-22 18:58:52 -0700682#ifdef __cplusplus
683}
684#endif
685
686#endif // _ANDROID_INPUT_H