mirror of
https://github.com/firewalkwithm3/Sensor-Watch.git
synced 2024-11-22 19:20:30 +08:00
Simulator: Add keyboard arrows as buttons shortcuts
This commit is contained in:
parent
bd9d792230
commit
b82d728937
|
@ -22,6 +22,8 @@
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "watch_extint.h"
|
#include "watch_extint.h"
|
||||||
#include "watch_main_loop.h"
|
#include "watch_main_loop.h"
|
||||||
|
|
||||||
|
@ -47,25 +49,45 @@ static EM_BOOL watch_invoke_interrupt_callback(const uint8_t button_id, watch_in
|
||||||
static EM_BOOL watch_invoke_key_callback(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData) {
|
static EM_BOOL watch_invoke_key_callback(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData) {
|
||||||
if (debug_console_focused || keyEvent->repeat) return EM_FALSE;
|
if (debug_console_focused || keyEvent->repeat) return EM_FALSE;
|
||||||
|
|
||||||
const char *key = keyEvent->key;
|
|
||||||
if (key[1] != 0) return EM_FALSE;
|
|
||||||
|
|
||||||
uint8_t button_id;
|
uint8_t button_id;
|
||||||
switch (key[0]) {
|
const char *key = keyEvent->key;
|
||||||
case 'A':
|
if (key[1] == 0) {
|
||||||
case 'a':
|
// event is from a plain letter key
|
||||||
button_id = BTN_ID_ALARM;
|
switch (key[0]) {
|
||||||
break;
|
case 'A':
|
||||||
case 'L':
|
case 'a':
|
||||||
case 'l':
|
button_id = BTN_ID_ALARM;
|
||||||
button_id = BTN_ID_LIGHT;
|
break;
|
||||||
break;
|
case 'L':
|
||||||
case 'M':
|
case 'l':
|
||||||
case 'm':
|
button_id = BTN_ID_LIGHT;
|
||||||
button_id = BTN_ID_MODE;
|
break;
|
||||||
break;
|
case 'M':
|
||||||
default:
|
case 'm':
|
||||||
return EM_FALSE;
|
button_id = BTN_ID_MODE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return EM_FALSE;
|
||||||
|
}
|
||||||
|
} else if (strncmp(key, "Arrow", 5) == 0) {
|
||||||
|
// event is from one of the arrow keys
|
||||||
|
switch(key[5]) {
|
||||||
|
case 'U': // ArrowUp
|
||||||
|
button_id = BTN_ID_LIGHT;
|
||||||
|
break;
|
||||||
|
case 'D': // ArrowDown
|
||||||
|
case 'L': // ArrowLeft
|
||||||
|
button_id = BTN_ID_MODE;
|
||||||
|
break;
|
||||||
|
case 'R': // ArrowRight
|
||||||
|
button_id = BTN_ID_ALARM;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return EM_FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// another kind of key
|
||||||
|
return EM_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
watch_interrupt_trigger trigger = eventType == EMSCRIPTEN_EVENT_KEYDOWN ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING;
|
watch_interrupt_trigger trigger = eventType == EMSCRIPTEN_EVENT_KEYDOWN ? INTERRUPT_TRIGGER_RISING : INTERRUPT_TRIGGER_FALLING;
|
||||||
|
|
Loading…
Reference in a new issue