GWT Export does not Prevent Default Key Presses
See original GitHub issueWhen I compile my libGDX project to target html
there are scripts to prevent default mouse operations, but not keyboard. This can be somewhat of a hassle for games where normally people use arrow keys.
I’ve been looking around and I tried multiple things (none of which worked) such as follows:
window.focus();
or
window.addEventListener("keydown", handleKeyDown(evt) {
// Prevent space and arrow keys:
if([32, 37, 38, 39, 40].indexOf(evt.keyCode) > -1) { evt.preventDefault(); }
});
or
handleKeyDown(evt) {
evt.preventDefault();
}
document.getElementById('embed-html').addEventListener("keydown", handleKeyDown(evt), false);
etc.
But it doesn’t seem to change anything. Any suggestions on what I may be doing wrong?
If you need to see my code it’s here. Basically everything within that {% if page.type == "libgdx" %}
statement is where my code is. And if you need the game page source-code is here, and the actual page is here.
Thanks!
Issue Analytics
- State:
- Created 9 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
GWT event prevent default not working in Java - Stack Overflow
I tried a little experiment on a normal web page. It turns out, that the MOUSEDOWN event doesn't do anything in that context...
Read more >[GWT] Documentation - Compile & Debug
When an application is running in development mode, the Java Virtual Machine (JVM) is actually executing the application code as compiled Java bytecode,...
Read more >Smart GWT Legacy Release Notes - SmartClient
When a ListGrid shows a filterEditor, default behavior is now to discard edits when the user hides a field. This matches 9.0 behavior...
Read more >GWT - Quick Guide - Tutorialspoint
If you do not have Java installed then you can install the Java Software ... For example, the Button widget has a default...
Read more >Why doesn't GWT just export everything automattically
In the GWT 3.0 it'll you can use JsInterfaces etcetera which is much better than GWT exporter and built into the compiler. It...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had a similar problem, i needed that the TAB key change the focus among text fields, but the canvas lost the focus when TAB was pressed. To achieve the goal I put a javascritp at onkeydown of the body of the index.html:
And made my screen class implements InputProcessor, so i built the logic to control the focus change on methods keyUp e keyDown, both starting with:
Just to be sure it won’t make side effects on other plataforms xD
It’s more a rusty workaround than a pretty solution, but I hope it helps.
Ok, found a solution myself: I had a typo in the code that went up fixing the problem(despite it throwing an error), but I don’t know why. So my full script looks like this: