diff options
| author | Tomas Andrle <tomovo@gmail.com> | 2025-10-10 00:57:17 +0200 |
|---|---|---|
| committer | Tomas Andrle <tomovo@gmail.com> | 2025-10-22 19:16:07 +0200 |
| commit | 8147fcafc1c4637357ad1696611d1700247144ab (patch) | |
| tree | 1741e4a50edee30e6550bd2fd842c065b07f7fec /sokol_app.h | |
| parent | df3d2b6990b7967df5503c807c03202ab6cc45e9 (diff) | |
handle apple tv remote button presses and some game controller inputs that can be used for menu navigation
Diffstat (limited to 'sokol_app.h')
| -rw-r--r-- | sokol_app.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sokol_app.h b/sokol_app.h index ed15d55f..dfd4620d 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -5556,6 +5556,45 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { - (BOOL)isOpaque { return YES; } +- (void)pressEvent:(UIPressType)press type:(sapp_event_type)type { + if (_sapp_events_enabled()) { + sapp_keycode key; + switch (press) { + case UIPressTypeUpArrow: key = SAPP_KEYCODE_UP; break; + case UIPressTypeDownArrow: key = SAPP_KEYCODE_DOWN; break; + case UIPressTypeLeftArrow: key = SAPP_KEYCODE_LEFT; break; + case UIPressTypeRightArrow: key = SAPP_KEYCODE_RIGHT; break; + case UIPressTypeSelect: key = SAPP_KEYCODE_ENTER; break; + case UIPressTypeMenu: key = SAPP_KEYCODE_MENU; break; + case UIPressTypePlayPause: key = SAPP_KEYCODE_MENU; break; + default: key = SAPP_KEYCODE_INVALID; break; + } + if (key != SAPP_KEYCODE_INVALID) { + _sapp_init_event(type); + _sapp.event.key_code = key; + _sapp.event.key_repeat = false; + _sapp.event.modifiers = 0; + _sapp_call_event(&_sapp.event); + } + } +} +- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { + for ( UIPress *press in presses ) { + [self pressEvent: press.type type: SAPP_EVENTTYPE_KEY_DOWN]; + } +} +- (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { +} +- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { + for ( UIPress *press in presses ) { + [self pressEvent: press.type type: SAPP_EVENTTYPE_KEY_UP]; + } +} +- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event { + for ( UIPress *press in presses ) { + [self pressEvent: press.type type: SAPP_EVENTTYPE_KEY_UP]; + } +} - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent*)event { _sapp_ios_touch_event(SAPP_EVENTTYPE_TOUCHES_BEGAN, touches, event); } |