v86 icon indicating copy to clipboard operation
v86 copied to clipboard

fix keyboard input in mobile browsers

Open SuperMaxusa opened this issue 8 months ago • 3 comments

Fixes #262 (and probably #1212) by adding input event handler, tested in Chrome and Firefox on Android.

SuperMaxusa avatar Apr 26 '25 20:04 SuperMaxusa

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

copy avatar May 01 '25 10:05 copy

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

v86-phonekb

EDIT: I sketched out a few ideas on how to fix it:

SuperMaxusa avatar May 01 '25 13:05 SuperMaxusa

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).

SuperMaxusa avatar May 13 '25 23:05 SuperMaxusa

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.

copy avatar Aug 09 '25 21:08 copy

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.

android-kbd

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.

SuperMaxusa avatar Aug 11 '25 14:08 SuperMaxusa

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.

SuperMaxusa avatar Aug 19 '25 14:08 SuperMaxusa

Squashed and merged, thanks!

copy avatar Aug 19 '25 22:08 copy