mirror of https://github.com/bjornbytes/lovr.git
Add isKeyDown
This commit is contained in:
parent
50b321fb64
commit
31ca502034
|
@ -114,10 +114,17 @@ static int l_lovrSystemRequestPermission(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSystemIsKeyDown(lua_State* L) {
|
||||
os_key key = luax_checkenum(L, 1, KeyboardKey, NULL);
|
||||
lua_pushboolean(L, lovrSystemIsKeyDown(key));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg lovrSystem[] = {
|
||||
{ "getOS", l_lovrSystemGetOS },
|
||||
{ "getCoreCount", l_lovrSystemGetCoreCount },
|
||||
{ "requestPermission", l_lovrSystemRequestPermission },
|
||||
{ "isKeyDown", l_lovrSystemIsKeyDown },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -4,7 +4,13 @@
|
|||
#include "util.h"
|
||||
#include <string.h>
|
||||
|
||||
static struct {
|
||||
bool initialized;
|
||||
bool pressedKeys[KEY_COUNT];
|
||||
} state;
|
||||
|
||||
static void onKeyboardEvent(os_button_action action, os_key key, uint32_t scancode, bool repeat) {
|
||||
state.pressedKeys[key] = (action == BUTTON_PRESSED);
|
||||
lovrEventPush((Event) {
|
||||
.type = action == BUTTON_PRESSED ? EVENT_KEYPRESSED : EVENT_KEYRELEASED,
|
||||
.data.key.code = key,
|
||||
|
@ -30,10 +36,6 @@ static void onPermissionEvent(os_permission permission, bool granted) {
|
|||
lovrEventPush(event);
|
||||
}
|
||||
|
||||
static struct {
|
||||
bool initialized;
|
||||
} state;
|
||||
|
||||
bool lovrSystemInit() {
|
||||
if (state.initialized) return false;
|
||||
os_on_key(onKeyboardEvent);
|
||||
|
@ -59,6 +61,10 @@ uint32_t lovrSystemGetCoreCount() {
|
|||
return os_get_core_count();
|
||||
}
|
||||
|
||||
bool lovrSystemIsKeyDown(os_key key) {
|
||||
return state.pressedKeys[key];
|
||||
}
|
||||
|
||||
void lovrSystemRequestPermission(Permission permission) {
|
||||
os_request_permission((os_permission) permission);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "core/os.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -12,3 +13,4 @@ void lovrSystemDestroy(void);
|
|||
const char* lovrSystemGetOS(void);
|
||||
uint32_t lovrSystemGetCoreCount(void);
|
||||
void lovrSystemRequestPermission(Permission permission);
|
||||
bool lovrSystemIsKeyDown(os_key key);
|
||||
|
|
Loading…
Reference in New Issue