Skip to content
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

[Bug]: hardware keyboard does not work with IME #635

Closed
knyipab opened this issue May 16, 2024 · 21 comments
Closed

[Bug]: hardware keyboard does not work with IME #635

knyipab opened this issue May 16, 2024 · 21 comments

Comments

@knyipab
Copy link
Contributor

knyipab commented May 16, 2024

Problem description

Not sure weather this counts as bug. However, hardware keyboard only types English characters and does not work with IME.

What steps will reproduce the bug?

Use any IME like Samsung keyboard with external keyboard to type.

What is the expected behavior?

I suppose users expect hardware keyboard to work with input methods.

A dumb approach might be reading the implementation in the source code of TextView in ASOP, but I don't find it easy.

@twaik
Copy link
Member

twaik commented May 16, 2024

What exactly do you mean? Works fine on my devices.

@knyipab
Copy link
Contributor Author

knyipab commented May 16, 2024

In the below video, I typed using hardware keyabord and tried with different input methods (e.g. simplified chinese, japanese and traditional chinese) but it only output English. Do you have different behaviour on your device?

Screen_Recording_20240517_000326_TermuxX11.2.mp4

@twaik
Copy link
Member

twaik commented May 16, 2024

Toggle extra keys bar and swipe it to see the text input.
Try to input something with additional keyboard there.
You will see exactly the same behaviour. Only English symbols.

@knyipab
Copy link
Contributor Author

knyipab commented May 16, 2024

Only with the help of EK bar text input, hardware keyboard + IME could work. They could not work directly with the LorieView. It is great and more natural to input into LorieView directly. I found RVNC Viewer seems to work well with hardware keyboard IME, perhaps they simply implement the TextView.

By the way, during my test, I found that Termux App could enable direct hardware keyboard IME after tapping the EK bar text input and then tapping into the terminal, for unknown reason. Shown in below video.

Screen_Recording_20240517_002454_Termux.mp4

And this does not happen in Termux:X11. Shown in below video.

Screen_Recording_20240517_001729_TermuxX11.mp4

@twaik
Copy link
Member

twaik commented May 16, 2024

For some reason on my device it works using real hardware keyboard but does not work with scrcpy in OTG mode. So actually I can not reproduce it on my device.

@twaik
Copy link
Member

twaik commented May 16, 2024

And now it works with scrcpy too. Adorable.

@twaik
Copy link
Member

twaik commented May 16, 2024

Ok, I got it. It works with scrcpy in OTG mode, but does not work scrcpy with regular input. It seems like scrcpy injects events as a virtual keyboard device and Samsung's IME does not want to treat this device as capable to use multi-layout input.

@knyipab
Copy link
Contributor Author

knyipab commented May 17, 2024

I have no clues about which part of code causing the bug because IME in hardware keyboard never work with Termux:X11, neither Gboard, for me since day 1. My device is Samsung Z Fold5 running One UI 6.1 Android 14.

Anything I can help debugging? Breakpoints? Logs? More test cases (I own a S21)?

@twaik
Copy link
Member

twaik commented May 17, 2024

I think we can try to get symbols from IME using InputConnection, but that may break regular input mechanisms of X11 programs. I am not sure if they will work at all.

@knyipab
Copy link
Contributor Author

knyipab commented May 17, 2024

Just tested and I don't think so.

I applied breakpoints on any methods of BaseInputConnection in #620 . It does not trigger any InputConnection methods when typing in hardware keyboard. I also tested on my S21 and it's just the same.

@twaik
Copy link
Member

twaik commented May 17, 2024

It should trigger commitText.

@knyipab
Copy link
Contributor Author

knyipab commented May 17, 2024

No, I can confirm that hardware keyboard on my devices does not trigger commitText at all. I tried tapping software keyboard, and that tapping triggers commitText.

@knyipab
Copy link
Contributor Author

knyipab commented May 17, 2024

Same no matter it is BT or USB (OTG) keyboard.

@twaik
Copy link
Member

twaik commented May 17, 2024

Try to remove onKeyPreIme method.

@knyipab
Copy link
Contributor Author

knyipab commented May 17, 2024

Where and how to? Searched and didn't find that method.

Tried @Override that method and return false for LorieView but still it doesn't trigger commitText, neither any methods of InputConnection.

@twaik
Copy link
Member

twaik commented May 17, 2024

Sorry, forgot the exact name.

@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
Activity a = getActivity();
return (a instanceof MainActivity) && ((MainActivity) a).handleKey(event);
}

@knyipab
Copy link
Contributor Author

knyipab commented May 17, 2024

Yes. By removing this method, the IME works perfectly! And tapping soft keyboard continues to work, not affected.

@knyipab
Copy link
Contributor Author

knyipab commented May 17, 2024

Any reason to call mLorieKeyListener.onKey instead of super.dispatchKeyEventPreIme? They do similar thing in my test except that the latter can also handle IME for hardware keypresses.

@twaik
Copy link
Member

twaik commented May 17, 2024

I am not sure why but there some devices (or IMEs) which modify key event data. I can make it optional if it causes problems.

@knyipab
Copy link
Contributor Author

knyipab commented May 17, 2024

Yes, please. That will be very helpful.

@twaik twaik closed this as completed in 3c8cc75 May 19, 2024
@knyipab
Copy link
Contributor Author

knyipab commented May 22, 2024

3c8cc75 does not work without setting outAttrs.inputType.

My previous test results are based on this PR #620 (cuz you mentioned BaseInputConnection at the beginning).

If you don't want to merge PR #620 any time soon, may consider to add this to LorieView.

    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
        return super.onCreateInputConnection(outAttrs);
    }

@termux termux locked and limited conversation to collaborators Jul 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants