Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
111.75k stars 10.7k forks source link

Non english keyboard layout #37

Closed elig0n closed 3 years ago

elig0n commented 6 years ago

I have hebrew keyboard layout on both my computer and my android keyboard that is in use but it wouldn't let me pass the letters. Any chance to fix this?

rom1v commented 6 years ago

Any change to fix this?

Probably not. Only ASCII and some accented characters work.

Except if someone finds a technical solution ;)

MiracleXYZ commented 6 years ago

I used to have the same issue but it disappeared through some "practice":

  1. Turn to AOSP and type some numbers like 1234 (that works fine).
  2. Type some letters. If it doesn't work, press shift key several times. (You may say a bunch of letters "crowding in".
  3. Turn to GBoard or other keyboards. It will work fine if you are lucky :)
wuairc commented 6 years ago

One possible technical solution is to write a customized input method manager. Vysor(an scrcpy alternative) does this. The input method manager can be installed and enabled by adb, without user interaction.

AndroidDeveloperLB commented 6 years ago

+1 on this. Wanted to write in Hebrew too, but failed. Are you sure it's impossible to use adb to pass unicode keys ?

vshymanskyy commented 6 years ago

@rom1v One of the possible options could be to create a custom keyboard, like NULL keyboard that I described here: https://github.com/Genymobile/scrcpy/issues/181, but with an ability to Input and Copy/Paste unicode. Probably not the easiest option, but at least something if there's no system API for such things. AFAIK, KDEConnect installs own keyboard.

AndroidDeveloperLB commented 6 years ago

I would prefer without this workaround...

giorgiobeggiora commented 6 years ago

I strongly hope this will be fixed soon

livin2 commented 5 years ago

https://remoboard.app/ example of this app may be help. pass unicode via an wireless server independent from adb server.

AndroidDeveloperLB commented 5 years ago

@livin2 This means I have to change my default keyboard, which means I might have less features than what I want to have. If an app is required, I would even install one that requires root, but having less features and having to switch keyboards as an alternative... This is just a hassle...

Is there maybe a way to do it using "monkeyrunner "? Someone wrote about this here: https://stackoverflow.com/a/20615725/878126

livin2 commented 5 years ago

If an app is required, I would even install one that requires root, but having less features and having to switch keyboards as an alternative... This is just a hassle...

feature like emoji mostly depend on the ime of computer.
and you can switch keyboards with adb shell in the script where you start scrcpy:

adb shell ime list -s 
adb shell ime set 【IME NAME】
adb connect 【xxx】
scrcpy -s 【xxx】
AndroidDeveloperLB commented 5 years ago

Yes, still a hassle. Once I disconnect from USB, I have to switch back to the keyboard I use. Besides, all this time that I use Scrcpy I won't have any of the features of the keyboard that I use.

pangliang commented 5 years ago

Refer to the Vysor method, add a custom ime to enter unicode characters

903

NewUserHa commented 4 years ago

I guess it may not be that easy and other apps may implement it successfully.

hope can input and copy/paste unicode characters via scrcpy window directly.

rom1v commented 4 years ago

hope can input and copy/paste unicode characters via scrcpy window directly.

Yes, this works. https://github.com/Genymobile/scrcpy#copy-paste

NewUserHa commented 4 years ago

I mean 'unicode directly'.

what about putting the key event to the IME if don't implement something new?

NewUserHa commented 4 years ago

I think if users are playing mobile game using scrcpy, they must need type texts sometimes. if the users are trying to type/paste chinese or japanese then scrcpy is unable to cover that needs. and I don't think scrcpy need other big features except this one.

rom1v commented 4 years ago

I don't think scrcpy need other big features except this one.

and #14 :wink:

NewUserHa commented 4 years ago

oh, I'm just reading it while you reply. the audio seems a bigger feature and some hard and a little important than current one. but when waking up the phone(cpu855) using scrcpy, I feel it recover from lag in the first seconds(on windows). I guess there could be problems if there's audio playing in the background.

AndroidDeveloperLB commented 4 years ago

Could copy-paste work method work for non-English? I tried now using it, but it didn't paste. It did succeed to copy it to the clipboard of the device though. Is there maybe an Android-supported key for pasting ? If so, maybe this could be a workaround for typing...

rom1v commented 4 years ago

When you Ctrl+Shift+v in the scrcpy window, the computer clipboard is copied to the device clipboard (exactly, without problems with special characters).

You can then long-press in any text area on your fevice and click in Copy.

AndroidDeveloperLB commented 4 years ago

@rom1v I know. That's why I wrote "It did succeed to copy it to the clipboard of the device though.". My question was if it's possible to do a real pasting, perhaps using some workaround of paste via a key.

rom1v commented 4 years ago

Please test #1426 (works on Android >= 7).

JulyMorning commented 4 years ago

any workarounds found?

npes87184 commented 4 years ago

POC that I implemented before.

https://github.com/npes87184/SocketIME

And its demo.

AndroidDeveloperLB commented 4 years ago

@npes87184 So this is by using a new keyboard app on the device, that has to be set as default, right?

rom1v commented 4 years ago

@npes87184 To keep things simple on the client side, I think we could do the following:

Tht way, the client always communicate to scrcpy-server only, which manages everything. And this doesn't delay scrcpy starting (except for text).

What do you think?

npes87184 commented 4 years ago

@npes87184 So this is by using a new keyboard app on the device, that has to be set as default, right?

In this POC, yes.

@npes87184 To keep things simple on the client side, I think we could do the following:

  • put the IME service class in scrcpy-server
  • if the user pass --use-ime (for example), then the scrcpy-server installs itself (programatically, it has shell permissions) asynchronously (if the same version is not already installed), without delaying video stream and control (except text events, which could be queued or ignored)
  • it then enables the IME and connects to it
  • once connected, all text events received by scrcpy-server are now forwarded to the IME
  • on cleanup, scrcpy-server restore the previous IME

Tht way, the client always communicate to scrcpy-server only, which manages everything. And this doesn't delay scrcpy starting (except for text).

What do you think?

I would say that this method is pretty well. However, there is a problem about UI. How do we "make" an area to let user enter words.

rom1v commented 4 years ago

However, there is a problem about UI. How do we "make" an area to let user enter words.

Oh, I've never used this kind of things. I don't really know how they work.

Isn't this area provided by the system, and give the resulting character as a "text event"?

Once we have the text event with UTF-8 content (typically for one "character", like for letters), we can inject it to the system using the IME without being limited to ASCII.

NewUserHa commented 4 years ago

and what about the physical keyboard? making user type on the device directly. and what about adding a text control let user input texts and copy to the device by scrcpy in bachground when user type enter. both ways will be better than panful installing anything.

AndroidDeveloperLB commented 4 years ago

Is there perhaps a way to achieve unicode key support by using accessibilityService? Maybe using dispatchKey() or something? Seems to me like a better thing, instead of having to use new keyboard and reset it...

npes87184 commented 4 years ago

However, there is a problem about UI. How do we "make" an area to let user enter words.

Oh, I've never used this kind of things. I don't really know how they work.

Isn't this area provided by the system, and give the resulting character as a "text event"?

Once we have the text event with UTF-8 content (typically for one "character", like for letters), we can inject it to the system using the IME without being limited to ASCII.

Oh, you misunderstand my question. My question is how do we design an area in SDL so that user can type in that area and send it to IME.

rom1v commented 4 years ago

https://wiki.libsdl.org/SDL_StartTextInput https://wiki.libsdl.org/Tutorials/TextInput (not tested)

AndroidDeveloperLB commented 4 years ago

@rom1v What's that?

vip-liutao commented 4 years ago

当手机打开投屏时,系统会自动添加wfd-uhid-device的物理键盘 这让scrcpy的input keyevent可以被输入法监听到 这很神奇,但是我不知道如何在不开启投屏的时候启用这个wfd-uhid-device物理键盘 视频测试经过地址: https://raw.githubusercontent.com/vip-liutao/scrcpy/main/keyboard.mkv

vip-liutao commented 4 years ago

当手机打开投屏时,系统会自动添加wfd-uhid-device的物理键盘 这让scrcpy的输入键事件可以被输入法监听到 这很神奇,但是我不知道如何在不开启投屏的时候启用这个wfd -uhid-device物理键盘 视频测试通过地址:https : //raw.githubusercontent.com/vip-liutao/scrcpy/main/keyboard.mkv

@rom1v

rom1v commented 4 years ago

How do you enable "wfd-uhid-device" in practice?

Refs:

omareg94 commented 4 years ago

When I activate raw key events mode (by pressing Ctrl+K) then try to type using Arabic (101) keyboard layout, I get messages like these on command line and no Arabic letters are passed to my Android device:

[server] WARN: Could not inject char u+0643 [server] WARN: Could not inject char u+064a [server] WARN: Could not inject char u+0641

AndroidDeveloperLB commented 4 years ago

Wait, does it mean scrcpy now supports unicode?

gaussandhisgun commented 3 years ago

I've probably just found a way to work around this. This can be added in newer builds with some --command-line-option to enable or disable. I am not a coding genius so let me explain in my bad English:

We create an invisible always-focused text field that tracks input. Its content always defaults to, say, >. If any symbol was inserted or some text was pasted, device clipboard copies somewhere where it can be accessed easily, then everything after > is put to device clipboard, then server KEYCODE_PASTEs clipboard into the phone, and then clipboard is set back to what we saved back there. If > suddenly disappears (probably because it was wiped out by user who pressed Backspace), server sends KEYCODE_BACKSPACE. And all the function keys/arrows/etc are passed as it is right now if possible.

rom1v commented 3 years ago

@gaussandhisgun Even without "invisible text field", I did this experiment earlier: https://github.com/Genymobile/scrcpy/pull/1426

cylee0909 commented 3 years ago

wether there is a way , we could hack 'hard keyboard' mode for input unicode chars? @rom1v

ibrahimhajjaj commented 3 years ago

Is there any progress on this?

epilys commented 3 years ago

EDIT: Code moved to repository: https://github.com/epilys/scrcpy-input.py I will leave the gist up to not screw up bookmarks etc.

Hello all, scrcpy was useless to me without unicode (greek) input so I made a small GUI app with python3 + tkinter using only standard library modules plus xclip and xdotool to copy the input text to system clipboard and paste it inside scrcpy with Alt-v

You can easily modify it to modify how the clipboard is set and how the key input is simulated (I included an example with xte in the comments)

Set up a macro to bring it up whenever you want unicode input using your favourite macro app.

Demo

demo

Usage

usage: scrcpy-input.py [-h] [-m] [-nh] [-ns] window_name

This tool copies your input to system clipboard and then synchronises it with
android's clipboard and pastes it with Alt-v command. Obviously this will
overwrite your clipboard contents. Make sure you focus on the text input on
the scrcpy window before you attempt to paste.

positional arguments:

  window_name      window name to target

optional arguments:
  -h, --help       show this help message and exit
  -m, --manual     don't auto send on ctrl+Enter
  -nh, --no-hide   don't auto hide on send
  -ns, --no-strip  don't auto strip whitespace on send

Source code

https://gist.github.com/epilys/89148373fd2fb0d1d50c941eda3ec6db

AndroidDeveloperLB commented 3 years ago

Doesn't it "contaminate" the clipboard history of the device?

Isn't it better to have some accessibility app installed, and send adb commands to it, to put the character?

epilys commented 3 years ago

@AndroidDeveloperLB yes it does since it syncs the clipboards. There are probably better solutions, but I made this in 2 hours without any knowledge about android or scrcpy.

AndroidDeveloperLB commented 3 years ago

@epilys I see.

@rom1v If you want, I can create an accessibility app. I just don't know how to make it secure, so that only via add (and maybe of a specific PC) it will allow to post the keys. I don't want the app to be insecure, letting other apps be able to post things... I could perhaps offer some kind of password-like solution, so that if whoever triggers the posting of keys don't use the correct password, the app will stop working, telling the user that something weird happened...

rom1v commented 3 years ago

Closed by #2632: a new option --hid-keyboard allows to simulate a physical keyboard via USB.

Advantages:

Limitations:

AndroidDeveloperLB commented 3 years ago

@rom1v What's special on Linux&USB , that sadly it works only in this scenario? Also, have you tried the solution of an accessibility app?

quyleanh commented 3 years ago

Wait for Windows support.

AlynxZhou commented 2 years ago

@rom1v What's special on Linux&USB , that sadly it works only in this scenario? Also, have you tried the solution of an accessibility app?

libusb does not work on Windows for Android HID, at least for myself.