Add scancode and key repeat arguments to key events;

This commit is contained in:
bjorn 2020-08-07 14:15:45 -06:00
parent 414c5b991d
commit 682633d98b
6 changed files with 22 additions and 8 deletions

View File

@ -130,9 +130,15 @@ static int nextEvent(lua_State* L) {
return 3;
case EVENT_KEYPRESSED:
luax_pushenum(L, KeyCodes, event.data.key.code);
lua_pushinteger(L, event.data.key.scancode);
lua_pushboolean(L, event.data.key.repeat);
return 4;
case EVENT_KEYRELEASED:
luax_pushenum(L, KeyCodes, event.data.key.code);
return 2;
lua_pushinteger(L, event.data.key.scancode);
return 3;
#ifdef LOVR_ENABLE_THREAD
case EVENT_THREAD_ERROR:

View File

@ -54,7 +54,7 @@ typedef void (*quitCallback)(void);
typedef void (*windowFocusCallback)(bool focused);
typedef void (*windowResizeCallback)(int width, int height);
typedef void (*mouseButtonCallback)(MouseButton button, ButtonAction action);
typedef void (*keyboardCallback)(KeyCode key, ButtonAction action);
typedef void (*keyboardCallback)(ButtonAction action, KeyCode key, uint32_t scancode, bool repeat);
bool lovrPlatformInit(void);
void lovrPlatformDestroy(void);

View File

@ -57,7 +57,10 @@ static int32_t onInputEvent(struct android_app* app, AInputEvent* event) {
default: return 0;
}
state.onKeyboardEvent(key, action);
uint32_t scancode = AKeyEvent_getScanCode(event);
bool repeat = AKeyEvent_getRepeatCount(event) > 0;
state.onKeyboardEvent(action, key, scancode, repeat);
return 1;
}

View File

@ -68,8 +68,9 @@ static void onKeyboardEvent(GLFWwindow* window, int k, int scancode, int a, int
case GLFW_KEY_F5: key = KEY_F5; break;
default: return;
}
ButtonAction action = (a == GLFW_PRESS) ? BUTTON_PRESSED : BUTTON_RELEASED;
glfwState.onKeyboardEvent(key, action);
ButtonAction action = (a == GLFW_RELEASE) ? BUTTON_RELEASED : BUTTON_PRESSED;
bool repeat = (a == GLFW_REPEAT);
glfwState.onKeyboardEvent(action, key, scancode, repeat);
}
}

View File

@ -13,10 +13,12 @@ static struct {
size_t head;
} state;
static void onKeyboardEvent(KeyCode key, ButtonAction action) {
static void onKeyboardEvent(ButtonAction action, KeyCode key, uint32_t scancode, bool repeat) {
lovrEventPush((Event) {
.type = action == BUTTON_PRESSED ? EVENT_KEYPRESSED : EVENT_KEYRELEASED,
.data.key.code = key
.data.key.code = key,
.data.key.scancode = scancode,
.data.key.repeat = repeat
});
}

View File

@ -58,7 +58,9 @@ typedef struct {
} ResizeEvent;
typedef struct {
int code;
uint32_t code;
uint32_t scancode;
bool repeat;
} KeyEvent;
typedef struct {