Skip to content

Commit

Permalink
Don't intercept key presses when on-screen keyboard is showing in web…
Browse files Browse the repository at this point in the history
… client.

This fixes after having entered some numbers, attempting to backspace everything leaves behinds several characters
  • Loading branch information
UnknownShadow200 committed Oct 30, 2019
1 parent adf557b commit 5d11ebb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Window.c
Expand Up @@ -3013,6 +3013,13 @@ EMSCRIPTEN_KEEPALIVE void Window_ProcessKeyChar(int charCode) {

static EM_BOOL Window_KeyPress(int type, const EmscriptenKeyboardEvent* ev, void* data) {
Window_CorrectFocus();
/* When on-screen keyboard is open, we don't want to intercept any key presses, */
/* because they should be sent to the HTML text input instead. */
/* If any keys are intercepted, this causes attempting to backspace all text */
/* later to not actually backspace everything. (because the HTML text input */
/* does not have these intercepted key presses in its text buffer) */
/* (e.g. chrome for android sends keypresses sometimes for '0' to '9' keys) */
if (keyboardOpen) return false;
Window_ProcessKeyChar(ev->charCode);
return true;
}
Expand Down Expand Up @@ -3197,9 +3204,12 @@ EMSCRIPTEN_KEEPALIVE void SendFakeBackspace(void) {
Input_SetPressed(KEY_BACKSPACE, false);
}

static bool keyboardOpen;
void Window_OpenKeyboard(void) {
if (!Input_TouchMode) return;
keyboardOpen = true;
Platform_LogConst("OPEN SESAME");

EM_ASM({
var elem = window.cc_inputElem;
if (!elem) {
Expand Down Expand Up @@ -3245,6 +3255,8 @@ void Window_SetKeyboardText(const String* text) {

void Window_CloseKeyboard(void) {
if (!Input_TouchMode) return;
keyboardOpen = false;

EM_ASM({
if (!window.cc_inputElem) return;
document.body.removeChild(window.cc_inputElem);
Expand Down

0 comments on commit 5d11ebb

Please sign in to comment.