blob: ce79cd489c35a2214c3ec3b0fa40a62bac25cf5c [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _ANDROID_INPUT_H
18#define _ANDROID_INPUT_H
19
20/******************************************************************
21 *
22 * IMPORTANT NOTICE:
23 *
24 * This file is part of Android's set of stable system headers
25 * exposed by the Android NDK (Native Development Kit).
26 *
27 * Third-party source AND binary code relies on the definitions
28 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
29 *
30 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
31 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
32 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
33 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
34 */
35
36/*
37 * Structures and functions to receive and process input events in
38 * native code.
39 *
40 * NOTE: These functions MUST be implemented by /system/lib/libui.so
41 */
42
43#include <sys/types.h>
44#include <android/keycodes.h>
Dianne Hackborn68267412010-07-02 18:52:01 -070045#include <android/looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070046
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/*
Jeff Brown46b9ac02010-04-22 18:58:52 -070052 * Key states (may be returned by queries about the current state of a
53 * particular key code, scan code or switch).
Jeff Brown46b9ac02010-04-22 18:58:52 -070054 */
55enum {
56 /* The key state is unknown or the requested key itself is not supported. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070057 AKEY_STATE_UNKNOWN = -1,
Jeff Brown46b9ac02010-04-22 18:58:52 -070058
59 /* The key is up. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070060 AKEY_STATE_UP = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -070061
62 /* The key is down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070063 AKEY_STATE_DOWN = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -070064
65 /* The key is down but is a virtual key press that is being emulated by the system. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070066 AKEY_STATE_VIRTUAL = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -070067};
68
69/*
70 * Meta key / modifer state.
71 */
72enum {
73 /* No meta keys are pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070074 AMETA_NONE = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -070075
76 /* This mask is used to check whether one of the ALT meta keys is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070077 AMETA_ALT_ON = 0x02,
Jeff Brown46b9ac02010-04-22 18:58:52 -070078
79 /* This mask is used to check whether the left ALT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070080 AMETA_ALT_LEFT_ON = 0x10,
Jeff Brown46b9ac02010-04-22 18:58:52 -070081
82 /* This mask is used to check whether the right ALT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070083 AMETA_ALT_RIGHT_ON = 0x20,
Jeff Brown46b9ac02010-04-22 18:58:52 -070084
85 /* This mask is used to check whether one of the SHIFT meta keys is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070086 AMETA_SHIFT_ON = 0x01,
Jeff Brown46b9ac02010-04-22 18:58:52 -070087
88 /* This mask is used to check whether the left SHIFT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070089 AMETA_SHIFT_LEFT_ON = 0x40,
Jeff Brown46b9ac02010-04-22 18:58:52 -070090
91 /* This mask is used to check whether the right SHIFT meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070092 AMETA_SHIFT_RIGHT_ON = 0x80,
Jeff Brown46b9ac02010-04-22 18:58:52 -070093
94 /* This mask is used to check whether the SYM meta key is pressed. */
Jeff Brownc5ed5912010-07-14 18:48:53 -070095 AMETA_SYM_ON = 0x04
Jeff Brown46b9ac02010-04-22 18:58:52 -070096};
97
98/*
99 * Input events.
100 *
101 * Input events are opaque structures. Use the provided accessors functions to
102 * read their properties.
103 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700104struct AInputEvent;
105typedef struct AInputEvent AInputEvent;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700106
107/*
108 * Input event types.
109 */
110enum {
111 /* Indicates that the input event is a key event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700112 AINPUT_EVENT_TYPE_KEY = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700113
114 /* Indicates that the input event is a motion event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700115 AINPUT_EVENT_TYPE_MOTION = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -0700116};
117
118/*
119 * Key event actions.
120 */
121enum {
122 /* The key has been pressed down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700123 AKEY_EVENT_ACTION_DOWN = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700124
125 /* The key has been released. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700126 AKEY_EVENT_ACTION_UP = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700127
128 /* Multiple duplicate key events have occurred in a row, or a complex string is
129 * being delivered. The repeat_count property of the key event contains the number
130 * of times the given key code should be executed.
131 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700132 AKEY_EVENT_ACTION_MULTIPLE = 2
Jeff Brown46b9ac02010-04-22 18:58:52 -0700133};
134
135/*
136 * Key event flags.
137 */
138enum {
139 /* This mask is set if the device woke because of this key event. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700140 AKEY_EVENT_FLAG_WOKE_HERE = 0x1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700141
142 /* This mask is set if the key event was generated by a software keyboard. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700143 AKEY_EVENT_FLAG_SOFT_KEYBOARD = 0x2,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700144
145 /* This mask is set if we don't want the key event to cause us to leave touch mode. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700146 AKEY_EVENT_FLAG_KEEP_TOUCH_MODE = 0x4,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700147
148 /* This mask is set if an event was known to come from a trusted part
149 * of the system. That is, the event is known to come from the user,
150 * and could not have been spoofed by a third party component. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700151 AKEY_EVENT_FLAG_FROM_SYSTEM = 0x8,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700152
153 /* This mask is used for compatibility, to identify enter keys that are
154 * coming from an IME whose enter key has been auto-labelled "next" or
155 * "done". This allows TextView to dispatch these as normal enter keys
156 * for old applications, but still do the appropriate action when
157 * receiving them. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700158 AKEY_EVENT_FLAG_EDITOR_ACTION = 0x10,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700159
160 /* When associated with up key events, this indicates that the key press
161 * has been canceled. Typically this is used with virtual touch screen
162 * keys, where the user can slide from the virtual key area on to the
163 * display: in that case, the application will receive a canceled up
164 * event and should not perform the action normally associated with the
165 * key. Note that for this to work, the application can not perform an
166 * action for a key until it receives an up or the long press timeout has
167 * expired. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700168 AKEY_EVENT_FLAG_CANCELED = 0x20,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700169
170 /* This key event was generated by a virtual (on-screen) hard key area.
171 * Typically this is an area of the touchscreen, outside of the regular
172 * display, dedicated to "hardware" buttons. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700173 AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY = 0x40,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700174
175 /* This flag is set for the first key repeat that occurs after the
176 * long press timeout. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700177 AKEY_EVENT_FLAG_LONG_PRESS = 0x80,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700178
Jeff Brownc5ed5912010-07-14 18:48:53 -0700179 /* Set when a key event has AKEY_EVENT_FLAG_CANCELED set because a long
Jeff Brown46b9ac02010-04-22 18:58:52 -0700180 * press action was executed while it was down. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700181 AKEY_EVENT_FLAG_CANCELED_LONG_PRESS = 0x100,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700182
Jeff Brownc5ed5912010-07-14 18:48:53 -0700183 /* Set for AKEY_EVENT_ACTION_UP when this event's key code is still being
Jeff Brown46b9ac02010-04-22 18:58:52 -0700184 * tracked from its initial down. That is, somebody requested that tracking
185 * started on the key down and a long press has not caused
186 * the tracking to be canceled. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700187 AKEY_EVENT_FLAG_TRACKING = 0x200
Jeff Brown46b9ac02010-04-22 18:58:52 -0700188};
189
190/*
191 * Motion event actions.
192 */
193
194/* Bit shift for the action bits holding the pointer index as
Jeff Brownc5ed5912010-07-14 18:48:53 -0700195 * defined by AMOTION_EVENT_ACTION_POINTER_INDEX_MASK.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700196 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700197#define AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8
Jeff Brown46b9ac02010-04-22 18:58:52 -0700198
199enum {
200 /* Bit mask of the parts of the action code that are the action itself.
201 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700202 AMOTION_EVENT_ACTION_MASK = 0xff,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700203
204 /* Bits in the action code that represent a pointer index, used with
Jeff Brownc5ed5912010-07-14 18:48:53 -0700205 * AMOTION_EVENT_ACTION_POINTER_DOWN and AMOTION_EVENT_ACTION_POINTER_UP. Shifting
206 * down by AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer
Jeff Brown46b9ac02010-04-22 18:58:52 -0700207 * index where the data for the pointer going up or down can be found.
208 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700209 AMOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700210
211 /* A pressed gesture has started, the motion contains the initial starting location.
212 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700213 AMOTION_EVENT_ACTION_DOWN = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700214
215 /* A pressed gesture has finished, the motion contains the final release location
216 * as well as any intermediate points since the last down or move event.
217 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700218 AMOTION_EVENT_ACTION_UP = 1,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700219
Jeff Brownc5ed5912010-07-14 18:48:53 -0700220 /* A change has happened during a press gesture (between AMOTION_EVENT_ACTION_DOWN and
221 * AMOTION_EVENT_ACTION_UP). The motion contains the most recent point, as well as
Jeff Brown46b9ac02010-04-22 18:58:52 -0700222 * any intermediate points since the last down or move event.
223 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700224 AMOTION_EVENT_ACTION_MOVE = 2,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700225
226 /* The current gesture has been aborted.
227 * You will not receive any more points in it. You should treat this as
228 * an up event, but not perform any action that you normally would.
229 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700230 AMOTION_EVENT_ACTION_CANCEL = 3,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700231
232 /* A movement has happened outside of the normal bounds of the UI element.
233 * This does not provide a full gesture, but only the initial location of the movement/touch.
234 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700235 AMOTION_EVENT_ACTION_OUTSIDE = 4,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700236
237 /* A non-primary pointer has gone down.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700238 * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700239 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700240 AMOTION_EVENT_ACTION_POINTER_DOWN = 5,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700241
242 /* A non-primary pointer has gone up.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700243 * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700244 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700245 AMOTION_EVENT_ACTION_POINTER_UP = 6
Jeff Brown46b9ac02010-04-22 18:58:52 -0700246};
247
248/*
249 * Motion event edge touch flags.
250 */
251enum {
252 /* No edges intersected */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700253 AMOTION_EVENT_EDGE_FLAG_NONE = 0,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700254
255 /* Flag indicating the motion event intersected the top edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700256 AMOTION_EVENT_EDGE_FLAG_TOP = 0x01,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700257
258 /* Flag indicating the motion event intersected the bottom edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700259 AMOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700260
261 /* Flag indicating the motion event intersected the left edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700262 AMOTION_EVENT_EDGE_FLAG_LEFT = 0x04,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700263
264 /* Flag indicating the motion event intersected the right edge of the screen. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700265 AMOTION_EVENT_EDGE_FLAG_RIGHT = 0x08
Jeff Brown46b9ac02010-04-22 18:58:52 -0700266};
267
268/*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700269 * Input sources.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700270 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700271 * The appropriate interpretation for an input event depends on its source.
272 * 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/*
300 * Input event accessors.
301 *
302 * Note that most functions can only be used on input events that are of a given type.
303 * Calling these functions on input events of other types will yield undefined behavior.
304 */
305
306/*** Accessors for all input events. ***/
307
308/* Get the input event type. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700309int32_t AInputEvent_getType(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700310
311/* Get the id for the device that an input event came from.
312 *
313 * Input events can be generated by multiple different input devices.
314 * Use the input device id to obtain information about the input
315 * device that was responsible for generating a particular event.
316 *
317 * An input device id of 0 indicates that the event didn't come from a physical device;
318 * other numbers are arbitrary and you shouldn't depend on the values.
319 * Use the provided input device query API to obtain information about input devices.
320 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700321int32_t AInputEvent_getDeviceId(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700322
Jeff Brownc5ed5912010-07-14 18:48:53 -0700323/* Get the input event source. */
324int32_t AInputEvent_getSource(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700325
326/*** Accessors for key events only. ***/
327
328/* Get the key event action. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700329int32_t AKeyEvent_getAction(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700330
331/* Get the key event flags. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700332int32_t AKeyEvent_getFlags(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700333
334/* Get the key code of the key event.
335 * This is the physical key that was pressed, not the Unicode character. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700336int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700337
338/* Get the hardware key id of this key event.
339 * These values are not reliable and vary from device to device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700340int32_t AKeyEvent_getScanCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700341
342/* Get the meta key state. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700343int32_t AKeyEvent_getMetaState(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700344
345/* Get the repeat count of the event.
346 * For both key up an key down events, this is the number of times the key has
347 * repeated with the first down starting at 0 and counting up from there. For
348 * multiple key events, this is the number of down/up pairs that have occurred. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700349int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700350
351/* Get the time of the most recent key down event, in the
352 * java.lang.System.nanoTime() time base. If this is a down event,
353 * this will be the same as eventTime.
354 * Note that when chording keys, this value is the down time of the most recently
355 * pressed key, which may not be the same physical key of this event. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700356int64_t AKeyEvent_getDownTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700357
358/* Get the time this event occurred, in the
359 * java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700360int64_t AKeyEvent_getEventTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700361
362/*** Accessors for motion events only. ***/
363
364/* Get the combined motion event action code and pointer index. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700365int32_t AMotionEvent_getAction(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700366
367/* Get the state of any meta / modifier keys that were in effect when the
368 * event was generated. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700369int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700370
371/* Get a bitfield indicating which edges, if any, were touched by this motion event.
372 * For touch events, clients can use this to determine if the user's finger was
373 * touching the edge of the display. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700374int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700375
376/* Get the time when the user originally pressed down to start a stream of
377 * position events, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700378int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700379
380/* Get the time when this specific event was generated,
381 * in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700382int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700383
Jeff Brown5c225b12010-06-16 01:53:36 -0700384/* Get the X coordinate offset.
385 * For touch events on the screen, this is the delta that was added to the raw
386 * screen coordinates to adjust for the absolute position of the containing windows
387 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700388float AMotionEvent_getXOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700389
390/* Get the precision of the Y coordinates being reported.
391 * For touch events on the screen, this is the delta that was added to the raw
392 * screen coordinates to adjust for the absolute position of the containing windows
393 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700394float AMotionEvent_getYOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700395
Jeff Brown46b9ac02010-04-22 18:58:52 -0700396/* Get the precision of the X coordinates being reported.
397 * You can multiply this number with an X coordinate sample to find the
398 * actual hardware value of the X coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700399float AMotionEvent_getXPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700400
401/* Get the precision of the Y coordinates being reported.
402 * You can multiply this number with a Y coordinate sample to find the
403 * actual hardware value of the Y coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700404float AMotionEvent_getYPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700405
406/* Get the number of pointers of data contained in this event.
407 * Always >= 1. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700408size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700409
410/* Get the pointer identifier associated with a particular pointer
411 * data index is this event. The identifier tells you the actual pointer
412 * number associated with the data, accounting for individual pointers
413 * going up and down since the start of the current gesture. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700414int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700415
Jeff Brown5c225b12010-06-16 01:53:36 -0700416/* Get the original raw X coordinate of this event.
417 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700418 * on the screen, before it had been adjusted for the containing window
419 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700420float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700421
Jeff Brown5c225b12010-06-16 01:53:36 -0700422/* Get the original raw X coordinate of this event.
423 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700424 * on the screen, before it had been adjusted for the containing window
425 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700426float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700427
428/* Get the current X coordinate of this event for the given pointer index.
429 * Whole numbers are pixels; the value may have a fraction for input devices
430 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700431float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700432
433/* Get the current Y coordinate of this event for the given pointer index.
434 * Whole numbers are pixels; the value may have a fraction for input devices
435 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700436float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700437
438/* Get the current pressure of this event for the given pointer index.
439 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
440 * however values higher than 1 may be generated depending on the calibration of
441 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700442float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700443
444/* Get the current scaled value of the approximate size for the given pointer index.
445 * This represents some approximation of the area of the screen being
446 * pressed; the actual value in pixels corresponding to the
447 * touch is normalized with the device specific range of values
448 * and scaled to a value between 0 and 1. The value of size can be used to
449 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700450float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700451
Jeff Brownc5ed5912010-07-14 18:48:53 -0700452/* Get the current length of the major axis of an ellipse that describes the touch area
453 * at the point of contact for the given pointer index. */
454float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index);
455
456/* Get the current length of the minor axis of an ellipse that describes the touch area
457 * at the point of contact for the given pointer index. */
458float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index);
459
460/* Get the current length of the major axis of an ellipse that describes the size
461 * of the approaching tool for the given pointer index.
462 * The tool area represents the estimated size of the finger or pen that is
463 * touching the device independent of its actual touch area at the point of contact. */
464float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index);
465
466/* Get the current length of the minor axis of an ellipse that describes the size
467 * of the approaching tool for the given pointer index.
468 * The tool area represents the estimated size of the finger or pen that is
469 * touching the device independent of its actual touch area at the point of contact. */
470float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index);
471
472/* Get the current orientation of the touch area and tool area in radians clockwise from
473 * vertical for the given pointer index.
474 * An angle of 0 degrees indicates that the major axis of contact is oriented
475 * upwards, is perfectly circular or is of unknown orientation. A positive angle
476 * indicates that the major axis of contact is oriented to the right. A negative angle
477 * indicates that the major axis of contact is oriented to the left.
478 * The full range is from -PI/4 radians (finger pointing fully left) to PI/4 radians
479 * (finger pointing fully right). */
480float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index);
481
Jeff Brown46b9ac02010-04-22 18:58:52 -0700482/* Get the number of historical points in this event. These are movements that
483 * have occurred between this event and the previous event. This only applies
Jeff Brownc5ed5912010-07-14 18:48:53 -0700484 * to AMOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700485 * Historical samples are indexed from oldest to newest. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700486size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700487
488/* Get the time that a historical movement occurred between this event and
489 * the previous event, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700490int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700491 size_t history_index);
492
Jeff Brown5c225b12010-06-16 01:53:36 -0700493/* Get the historical raw X coordinate of this event for the given pointer index that
494 * occurred between this event and the previous motion event.
495 * For touch events on the screen, this is the original location of the event
496 * on the screen, before it had been adjusted for the containing window
497 * and views.
498 * Whole numbers are pixels; the value may have a fraction for input devices
499 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700500float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700501
502/* Get the historical raw Y coordinate of this event for the given pointer index that
503 * occurred between this event and the previous motion event.
504 * For touch events on the screen, this is the original location of the event
505 * on the screen, before it had been adjusted for the containing window
506 * and views.
507 * Whole numbers are pixels; the value may have a fraction for input devices
508 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700509float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700510
Jeff Brown46b9ac02010-04-22 18:58:52 -0700511/* Get the historical X coordinate of this event for the given pointer index that
512 * occurred between this event and the previous motion event.
513 * Whole numbers are pixels; the value may have a fraction for input devices
514 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700515float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700516 size_t history_index);
517
518/* Get the historical Y coordinate of this event for the given pointer index that
519 * occurred between this event and the previous motion event.
520 * Whole numbers are pixels; the value may have a fraction for input devices
521 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700522float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700523 size_t history_index);
524
525/* Get the historical pressure of this event for the given pointer index that
526 * occurred between this event and the previous motion event.
527 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
528 * however values higher than 1 may be generated depending on the calibration of
529 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700530float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700531 size_t history_index);
532
533/* Get the current scaled value of the approximate size for the given pointer index that
534 * occurred between this event and the previous motion event.
535 * This represents some approximation of the area of the screen being
536 * pressed; the actual value in pixels corresponding to the
537 * touch is normalized with the device specific range of values
538 * and scaled to a value between 0 and 1. The value of size can be used to
539 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700540float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700541 size_t history_index);
542
Jeff Brownc5ed5912010-07-14 18:48:53 -0700543/* Get the historical length of the major axis of an ellipse that describes the touch area
544 * at the point of contact for the given pointer index that
545 * occurred between this event and the previous motion event. */
546float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index,
547 size_t history_index);
548
549/* Get the historical length of the minor axis of an ellipse that describes the touch area
550 * at the point of contact for the given pointer index that
551 * occurred between this event and the previous motion event. */
552float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index,
553 size_t history_index);
554
555/* Get the historical length of the major axis of an ellipse that describes the size
556 * of the approaching tool for the given pointer index that
557 * occurred between this event and the previous motion event.
558 * The tool area represents the estimated size of the finger or pen that is
559 * touching the device independent of its actual touch area at the point of contact. */
560float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index,
561 size_t history_index);
562
563/* Get the historical length of the minor axis of an ellipse that describes the size
564 * of the approaching tool for the given pointer index that
565 * occurred between this event and the previous motion event.
566 * The tool area represents the estimated size of the finger or pen that is
567 * touching the device independent of its actual touch area at the point of contact. */
568float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index,
569 size_t history_index);
570
571/* Get the historical orientation of the touch area and tool area in radians clockwise from
572 * vertical for the given pointer index that
573 * occurred between this event and the previous motion event.
574 * An angle of 0 degrees indicates that the major axis of contact is oriented
575 * upwards, is perfectly circular or is of unknown orientation. A positive angle
576 * indicates that the major axis of contact is oriented to the right. A negative angle
577 * indicates that the major axis of contact is oriented to the left.
578 * The full range is from -PI/4 radians (finger pointing fully left) to PI/4 radians
579 * (finger pointing fully right). */
580float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index,
581 size_t history_index);
582
583
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700584/*
585 * Input queue
586 *
587 * An input queue is the facility through which you retrieve input
588 * events.
589 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700590struct AInputQueue;
591typedef struct AInputQueue AInputQueue;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700592
593/*
Dianne Hackborn85448bb2010-07-07 14:27:31 -0700594 * Add this input queue to a looper for processing. See
595 * ALooper_addFd() for information on the callback and data params.
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700596 */
Dianne Hackborn68267412010-07-02 18:52:01 -0700597void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
Dianne Hackborn85448bb2010-07-07 14:27:31 -0700598 ALooper_callbackFunc* callback, void* data);
Dianne Hackborn68267412010-07-02 18:52:01 -0700599
600/*
601 * Remove the input queue from the looper it is currently attached to.
602 */
603void AInputQueue_detachLooper(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700604
605/*
606 * Returns true if there are one or more events available in the
607 * input queue. Returns 1 if the queue has events; 0 if
608 * it does not have events; and a negative value if there is an error.
609 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700610int AInputQueue_hasEvents(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700611
612/*
613 * Returns the next available event from the queue. Returns a negative
614 * value if no events are available or an error has occurred.
615 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700616int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700617
618/*
619 * Report that dispatching has finished with the given event.
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700620 * This must be called after receiving an event with AInputQueue_get_event().
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700621 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700622void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700623
Jeff Brown46b9ac02010-04-22 18:58:52 -0700624#ifdef __cplusplus
625}
626#endif
627
628#endif // _ANDROID_INPUT_H