fix keyboard input in mobile browsers
Fixes #262 (and probably #1212) by adding input event handler, tested in Chrome and Firefox on Android.
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 e.preventDefault().
It would be nice if we could find a way to "downgrade" to using the input event gracefully, instead of checking the user agent. Maybe something like this:
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
The only differences seems to be that the new version scrolls to the top of the screen.
Same on Android, it because phone_keyboard always spawns at the top of page and browser focuses on it while typing.
https://github.com/copy/v86/blob/a3840e32b30d7005f2e7533a557b769333127425/src/browser/main.js#L2590-L2592
EDIT: I sketched out a few ideas on how to fix it:
- make a
DummyScreenAdapter.update_cursorhook and movephone_keyboardto the current row - move
phone_keyboardto wherescreen_containerwas pressed
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).
Thanks for the update! I've pushed the latest version here for testing again: https://copy.sh/v86-staging/?profile=buildroot
So far I doubt if it works with a physical keyboard (on iOS/Android).
In my testing, Safari on iOS sent proper e.code (like desktop browsers), so I would expect physical keyboards to work.
I spotted a minor regression, besides that this looks good to merge. Would be good to get some more testing in.
In my testing, Safari on iOS sent proper e.code (like desktop browsers), so I would expect physical keyboards to work.
Tested on Android-x86 9.0 VM: with default physical keyboard Firefox 141 and Chrome 138 also sent proper e.code with and without Desktop Mode.
The keyboard works properly on https://copy.sh/v86. https://copy.sh/v86-staging and https://github.com/copy/v86/pull/1317/commits/c5730de39325dd3f8de0d0ac984187676de16f79, as expected. The mouse cursor locks on click, just like on the desktop browsers.
I got an physical keyboard and mouse for my Android 12 device, keyboard input works properly on https://copy.sh/v86-staging and on this PR (in Firefox and Chrome). The arrow keys, Ctrl and Shift also work.
A few notes about mouse support: "Lock mouse" only works for me in Firefox (maybe because I tested on a phone?), but the mouse moves buggy.
Squashed and merged, thanks!