Skip to content

Conversation

SuperMaxusa
Copy link
Contributor

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

@copy
Copy link
Owner

copy commented May 1, 2025

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

@SuperMaxusa
Copy link
Contributor Author

SuperMaxusa commented May 1, 2025

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.

v86/src/browser/main.js

Lines 2590 to 2592 in a3840e3

// stop mobile browser from scrolling into view when the keyboard is shown
phone_keyboard.style.top = document.body.scrollTop + 100 + "px";
phone_keyboard.style.left = document.body.scrollLeft + 100 + "px";

v86-phonekb

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

@SuperMaxusa
Copy link
Contributor Author

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

Copy link
Owner

@copy copy left a 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.

@copy
Copy link
Owner

copy commented Aug 9, 2025

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.

@SuperMaxusa
Copy link
Contributor Author

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 c5730de, as expected. The mouse cursor locks on click, just like on the desktop browsers.

@SuperMaxusa
Copy link
Contributor Author

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.

fix onclick handler, phone_keyboard follows text mode cursor
always show phone keyboard
@copy copy force-pushed the mobile-keyboard branch from c5730de to 13f13ff Compare August 19, 2025 22:29
@copy copy merged commit 2482a99 into copy:master Aug 19, 2025
2 checks passed
@copy
Copy link
Owner

copy commented Aug 19, 2025

Squashed and merged, thanks!

@SuperMaxusa SuperMaxusa deleted the mobile-keyboard branch August 20, 2025 06:35
@SuperMaxusa SuperMaxusa mentioned this pull request Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

android keyboard not working
2 participants