MCPcopy Create free account
hub / github.com/android/ndk-samples / _process_keys

Function _process_keys

endless-tunnel/app/src/main/cpp/input_util.cpp:108–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108static bool _process_keys(bool isJoy, AInputEvent* event,
109 CookedEventCallback callback) {
110 if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY) {
111 int action = AKeyEvent_getAction(event);
112 int code = _translate_keycode(AKeyEvent_getKeyCode(event));
113 bool handled = code >= 0;
114 if (code >= 0 && action == AKEY_EVENT_ACTION_DOWN) {
115 _report_key_state(code, true, callback);
116 } else if (code >= 0 && action == AKEY_EVENT_ACTION_UP) {
117 _report_key_state(code, false, callback);
118 }
119 return handled;
120 } else if (isJoy) {
121 // use joystick axes to emulate directional key events (we could leave this
122 // up to the platform, but joystick-to-dpad conversion doesn't work
123 // on NDK on older devices, so we implement manually for maximum
124 // compatibility)
125 float x = AMotionEvent_getX(event, 0);
126 float y = AMotionEvent_getY(event, 0);
127 if (_getAxisValue) {
128 // take the hat switches into account too, so that either the
129 // regular axes or the hat axes can be used to navigate UIs
130 x += _getAxisValue(event, AXIS_HAT_X, 0);
131 y += _getAxisValue(event, AXIS_HAT_Y, 0);
132 x = Clamp(x, -1.0f, 1.0f);
133 y = Clamp(y, -1.0f, 1.0f);
134 }
135 _report_key_states_from_axes(x, y, callback);
136 return true;
137 }
138 return false;
139}
140
141static void _look_up_motion_range(int deviceId, int source, float* outMinX,
142 float* outMaxX, float* outMinY,

Callers 2

CookEvent_JoyFunction · 0.85
CookEventFunction · 0.85

Calls 4

_translate_keycodeFunction · 0.85
_report_key_stateFunction · 0.85
ClampFunction · 0.85

Tested by

no test coverage detected