-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix keyboard input in mobile browsers #1317
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
base: master
Are you sure you want to change the base?
Conversation
Thanks, this looks like a good approach! We could use some help with testing. I've deployed this version here: https://copy.sh/v86-staging/ Testing on ios: Both versions open the OS keyboard and work fine. The only differences seems to be that the new version scrolls to the top of the screen. This probably needs an It would be nice if we could find a way to "downgrade" to using the keydown:
if(e.code === "Unspecified")
{
// let the input handler run
return;
}
// call preventDefault here to prevent the input handler
// or, if that is not robust, disable the input handler until the next keyup event |
Same on Android, it because Lines 2590 to 2592 in a3840e3
EDIT: I sketched out a few ideas on how to fix it:
|
I pushed a fix to prevent screen scrolling and tried to fix keyboard and mouse in graphical OSes (on copy.sh/v86 it always opens the keyboard). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the delay in reviewing this. I would still like to get this merged, but I'm not sure about the approach. See the comments below.
src/browser/main.js
Outdated
const scale = parseFloat($("scale").value) || 1; | ||
|
||
phone_keyboard.style.top = Math.floor(window.scrollY + screen_pos.y + row * 16 * scale) + "px"; | ||
phone_keyboard.style.left = Math.floor(window.scrollX + screen_pos.x + (col - 1) * 8 * scale) + "px"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code looks fragile with the hard-coded font size and adhoc scaling detection. Could we use the graphical mode codepath for this (always moving the element into viewport)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will return the movement by touch coords.
src/browser/keyboard.js
Outdated
window.addEventListener("keyup", keyup_handler, false); | ||
window.addEventListener("keydown", keydown_handler, false); | ||
window.addEventListener("blur", blur_handler, false); | ||
if(IS_MOBILE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of mobile detection based on user-agents. It can break under many circumstances, for example if the user uses a bluetooth keyboard, alternative keyboard app or alternative browser.
I wonder if we could instead implement feature detection, e.g.:
- only registering the
input
event whenUnidentified
orProcess
key values are detected - registering the
input
event unconditionally, but cancelling it usingpreventDefault
in the other event handlers whenUnidentified
orProcess
key values are detected - any other ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- only registering the
input
event when Unidentified or Process key values are detected
This idea sounds good, but not sure about IME in desktop browsers. (upd: that's only affects non-English layouts)
Downgrading keyup -> input
(call return
, then go to input
) doesn't work in Firefox Mobile for me (it's required for Backspace
key).
Fixes #262 (and probably #1212) by adding
input
event handler, tested in Chrome and Firefox on Android.