key releases
This commit is contained in:
@@ -1066,6 +1066,10 @@ int main() {
|
|||||||
double tickDelay = 0.05;
|
double tickDelay = 0.05;
|
||||||
double tickClock = 0;
|
double tickClock = 0;
|
||||||
|
|
||||||
|
struct {int key; nn_codepoint unicode;} keybuf[512];
|
||||||
|
memset(keybuf, 0, sizeof(keybuf));
|
||||||
|
size_t keycap = sizeof(keybuf) / sizeof(keybuf[0]);
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
if(WindowShouldClose()) break;
|
if(WindowShouldClose()) break;
|
||||||
|
|
||||||
@@ -1112,6 +1116,9 @@ int main() {
|
|||||||
nn_codepoint unicode = GetCharPressed();
|
nn_codepoint unicode = GetCharPressed();
|
||||||
|
|
||||||
if(keycode == 0 && unicode == 0) break;
|
if(keycode == 0 && unicode == 0) break;
|
||||||
|
|
||||||
|
keybuf[keycode].key = keycode;
|
||||||
|
keybuf[keycode].unicode = unicode;
|
||||||
|
|
||||||
if(keycode != 0) {
|
if(keycode != 0) {
|
||||||
if(keycode == KEY_ENTER) unicode = '\r';
|
if(keycode == KEY_ENTER) unicode = '\r';
|
||||||
@@ -1122,6 +1129,16 @@ int main() {
|
|||||||
nn_pushKeyDown(c, "mainKB", unicode, keycode_to_oc(keycode), player);
|
nn_pushKeyDown(c, "mainKB", unicode, keycode_to_oc(keycode), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(size_t i = 0; i < keycap; i++) {
|
||||||
|
if(keybuf[i].key != 0) {
|
||||||
|
if(IsKeyReleased(keybuf[i].key)) {
|
||||||
|
int key = keycode_to_oc(keybuf[i].key);
|
||||||
|
keybuf[i].key = 0;
|
||||||
|
nn_pushKeyUp(c, "mainKB", keybuf[i].unicode, key, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tickClock -= GetFrameTime();
|
tickClock -= GetFrameTime();
|
||||||
|
|
||||||
if(tickClock <= 0) {
|
if(tickClock <= 0) {
|
||||||
|
|||||||
@@ -3640,7 +3640,7 @@ nn_Exit nn_pushKeyDown(nn_Computer *computer, const char *keyboardAddress, nn_co
|
|||||||
|
|
||||||
nn_Exit nn_pushKeyUp(nn_Computer *computer, const char *keyboardAddress, nn_codepoint charcode, int keycode, const char *player) {
|
nn_Exit nn_pushKeyUp(nn_Computer *computer, const char *keyboardAddress, nn_codepoint charcode, int keycode, const char *player) {
|
||||||
if(!nn_hasUser(computer, player)) return NN_OK;
|
if(!nn_hasUser(computer, player)) return NN_OK;
|
||||||
nn_Exit err = nn_pushstring(computer, "key_down");
|
nn_Exit err = nn_pushstring(computer, "key_up");
|
||||||
if(err) return err;
|
if(err) return err;
|
||||||
err = nn_pushstring(computer, keyboardAddress);
|
err = nn_pushstring(computer, keyboardAddress);
|
||||||
if(err) return err;
|
if(err) return err;
|
||||||
|
|||||||
Reference in New Issue
Block a user