Closed Ohmnivore closed 6 years ago
Another example, the up and down arrow keys will scroll the page in Chrome but not in Firefox.
Adding the following snippet to the page fixed the ctrl+s
and the arrow keys issues for me:
document.addEventListener('keydown', (event) => {
event.preventDefault();
});
However, ctrl-w
actually closes the tab in Chrome and Firefox irrespective of preventDefault()
and they have no intent of changing that. It's best to just not use ctrl
then.
Btw, I'm having a similar problem in Chrome on Windows in my Tiny Emulators: https://floooh.github.io/tiny8bit/, where Chrome intercepts the F1 key and shows the Help. I'll have a look if this fix of yours also fixes the problem I have there.
Thanks!
Np!
Btw I can't reproduce the F1
Help issue you mention on https://floooh.github.io/tiny8bit/atom.html and https://floooh.github.io/tiny8bit/c64.html for example. The function keys are well contained inside the tab, no funky behavior.
I've tried on Windows 10 on versions 68.0.3440.106 (Official Build) (64-bit)
and 69.0.3497.92 (Official Build) (64-bit)
(latest as of today).
I might just have had this fixed when you tested ;) At least I found out now what the problem is, it's about whether the key events are marked as 'consumed' by the event handler or not. If an event is consumed, the browser will ignore the event. Unfortunately I cannot simply mark all key events as 'consumed', since then I wouldn't get 'cooked' character key events (basically all the alpha-numeric stuff).
So what I'm doing now in sokol_app.h is a big switch case, I need to add the same to Oryol (in fact, I'll do this now) :)
Ok, it's in this commit: 064560193adb58b117328a78f224557a48af285b
This fixes problems like the arrows keys scrolling the page (but I'm not sure about the Ctrl key, you'd need to check this).
Your global preventDefault() fix is still necessary if you don't use the Input module (as then Oryol completely ignores any browser input events).
I'm using Windows 10. The issue can be reproduced using this sample: http://floooh.github.io/oryol/asmjs/TestInput.html
In Firefox if I press
Ctrl
ands
nothing special happens.In Chrome this will pop open a "Save As" dialog, which is unwanted behavior from my perspective.
My control scheme uses the
Ctrl
key so this is an inconvenience.