Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text input focus messing with the input manager #7013

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Extensions/TextInput/textinputruntimeobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,16 @@ namespace gdjs {
}

focus(): void {
if (!this.isFocused()) {
// If the input was not previously focused, reset input manager because there is
// no reason to maintain its state. It avoids bugs where a key is pressed, the text
// input is focused and then the input manager does not have access to the keyup event
// and considers the key still pressed.
this.getInstanceContainer()
.getGame()
.getInputManager()
.clearAllPressedKeys();
}
this._renderer.focus();
}
}
Expand Down
8 changes: 8 additions & 0 deletions GDJS/Runtime/inputmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,14 @@ namespace gdjs {
return this.getMouseWheelDelta() < 0;
}

/**
* Clears all stored pressed keys without making the keys go through
* the release state.
*/
clearAllPressedKeys(): void {
this._pressedKeys.clear();
}

static _allTouchIds: Array<integer> = [];
}
}
Loading