mirror of https://github.com/bjornbytes/lovr.git
Add scancode and key repeat arguments to key events;
This commit is contained in:
parent
414c5b991d
commit
682633d98b
|
@ -130,9 +130,15 @@ static int nextEvent(lua_State* L) {
|
||||||
return 3;
|
return 3;
|
||||||
|
|
||||||
case EVENT_KEYPRESSED:
|
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:
|
case EVENT_KEYRELEASED:
|
||||||
luax_pushenum(L, KeyCodes, event.data.key.code);
|
luax_pushenum(L, KeyCodes, event.data.key.code);
|
||||||
return 2;
|
lua_pushinteger(L, event.data.key.scancode);
|
||||||
|
return 3;
|
||||||
|
|
||||||
#ifdef LOVR_ENABLE_THREAD
|
#ifdef LOVR_ENABLE_THREAD
|
||||||
case EVENT_THREAD_ERROR:
|
case EVENT_THREAD_ERROR:
|
||||||
|
|
|
@ -54,7 +54,7 @@ typedef void (*quitCallback)(void);
|
||||||
typedef void (*windowFocusCallback)(bool focused);
|
typedef void (*windowFocusCallback)(bool focused);
|
||||||
typedef void (*windowResizeCallback)(int width, int height);
|
typedef void (*windowResizeCallback)(int width, int height);
|
||||||
typedef void (*mouseButtonCallback)(MouseButton button, ButtonAction action);
|
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);
|
bool lovrPlatformInit(void);
|
||||||
void lovrPlatformDestroy(void);
|
void lovrPlatformDestroy(void);
|
||||||
|
|
|
@ -57,7 +57,10 @@ static int32_t onInputEvent(struct android_app* app, AInputEvent* event) {
|
||||||
default: return 0;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,9 @@ static void onKeyboardEvent(GLFWwindow* window, int k, int scancode, int a, int
|
||||||
case GLFW_KEY_F5: key = KEY_F5; break;
|
case GLFW_KEY_F5: key = KEY_F5; break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
ButtonAction action = (a == GLFW_PRESS) ? BUTTON_PRESSED : BUTTON_RELEASED;
|
ButtonAction action = (a == GLFW_RELEASE) ? BUTTON_RELEASED : BUTTON_PRESSED;
|
||||||
glfwState.onKeyboardEvent(key, action);
|
bool repeat = (a == GLFW_REPEAT);
|
||||||
|
glfwState.onKeyboardEvent(action, key, scancode, repeat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,12 @@ static struct {
|
||||||
size_t head;
|
size_t head;
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
static void onKeyboardEvent(KeyCode key, ButtonAction action) {
|
static void onKeyboardEvent(ButtonAction action, KeyCode key, uint32_t scancode, bool repeat) {
|
||||||
lovrEventPush((Event) {
|
lovrEventPush((Event) {
|
||||||
.type = action == BUTTON_PRESSED ? EVENT_KEYPRESSED : EVENT_KEYRELEASED,
|
.type = action == BUTTON_PRESSED ? EVENT_KEYPRESSED : EVENT_KEYRELEASED,
|
||||||
.data.key.code = key
|
.data.key.code = key,
|
||||||
|
.data.key.scancode = scancode,
|
||||||
|
.data.key.repeat = repeat
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,9 @@ typedef struct {
|
||||||
} ResizeEvent;
|
} ResizeEvent;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int code;
|
uint32_t code;
|
||||||
|
uint32_t scancode;
|
||||||
|
bool repeat;
|
||||||
} KeyEvent;
|
} KeyEvent;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in New Issue