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

No cyrillic keyboard input and typing for Linux #193

Closed
Maboroshy opened this issue Nov 8, 2019 · 8 comments
Closed

No cyrillic keyboard input and typing for Linux #193

Maboroshy opened this issue Nov 8, 2019 · 8 comments

Comments

@Maboroshy
Copy link

I use Manjaro Linux with Plasma DE and X.org Server 1.20.5. There are US English and Russian keyboard layouts on my system.

pynput work ok with US English but with Russian:

  • input is recognized as a corresponding US English layout keys: q instead of й which is on the same key;
  • pynput.keyboard.Controller().type('абв') does nothing
xev output for `абв` looks ok... KeyPress event, serial 40, synthetic NO, window 0x6600001, root 0x6ce, subw 0x0, time 1433257, (-446,410), root:(472,447), state 0x2000, keycode 41 (keysym 0x6c1, Cyrillic_a), same_screen YES, XLookupString gives 2 bytes: (d0 b0) "а" XmbLookupString gives 2 bytes: (d0 b0) "а" XFilterEvent returns: False

KeyRelease event, serial 40, synthetic NO, window 0x6600001,
root 0x6ce, subw 0x0, time 1433335, (-446,410), root:(472,447),
state 0x2000, keycode 41 (keysym 0x6c1, Cyrillic_a), same_screen YES,
XLookupString gives 2 bytes: (d0 b0) "а"
XFilterEvent returns: False

KeyPress event, serial 40, synthetic NO, window 0x6600001,
root 0x6ce, subw 0x0, time 1433713, (-446,410), root:(472,447),
state 0x2000, keycode 59 (keysym 0x6c2, Cyrillic_be), same_screen YES,
XLookupString gives 2 bytes: (d0 b1) "б"
XmbLookupString gives 2 bytes: (d0 b1) "б"
XFilterEvent returns: False

KeyRelease event, serial 40, synthetic NO, window 0x6600001,
root 0x6ce, subw 0x0, time 1433793, (-446,410), root:(472,447),
state 0x2000, keycode 59 (keysym 0x6c2, Cyrillic_be), same_screen YES,
XLookupString gives 2 bytes: (d0 b1) "б"
XFilterEvent returns: False

KeyPress event, serial 40, synthetic NO, window 0x6600001,
root 0x6ce, subw 0x0, time 1434147, (-446,410), root:(472,447),
state 0x2000, keycode 40 (keysym 0x6d7, Cyrillic_ve), same_screen YES,
XLookupString gives 2 bytes: (d0 b2) "в"
XmbLookupString gives 2 bytes: (d0 b2) "в"
XFilterEvent returns: False

KeyRelease event, serial 40, synthetic NO, window 0x6600001,
root 0x6ce, subw 0x0, time 1434227, (-446,410), root:(472,447),
state 0x2000, keycode 40 (keysym 0x6d7, Cyrillic_ve), same_screen YES,
XLookupString gives 2 bytes: (d0 b2) "в"
XFilterEvent returns: False

@moses-palmer
Copy link
Owner

That seems like a strange bug; there is even a test for it here. Does running the test suite fail as well?

@Maboroshy
Copy link
Author

That test fails on my system:

FAIL: test_type_nonascii (tests.keyboard_controller_tests.KeyboardControllerTest)
Asserts that type works for a non-ascii strings

Traceback (most recent call last):
File "/home/mbr/Код/pynput/git/tests/keyboard_controller_tests.py", line 289, in test_type_nonascii
u'Компьютерная клавиатура')
File "/home/mbr/Код/pynput/git/tests/keyboard_controller_tests.py", line 95, in assert_input
self.assertIn(expected, collect(), failure_message)
AssertionError: 'Компьютерная клавиатура' not found in (' ',) : Failed to type Russian string

Ran 17 tests in 5.124s

FAILED (failures=1)

@moses-palmer
Copy link
Owner

Thank you for your help!

What output do you get from xev when you run python -c "import pynput; pynput.keyboard.Controller().type('абв')?

@Maboroshy
Copy link
Author

Maboroshy commented Nov 29, 2019

I'm not sure I know how to get the data.
xev creates a dummy X window and prints events only for this window.
When I manually attach xev to a terminal window by xev -id I see only some MappingNotify events while the command runs, no key events except for return key I press to run a command. I've run it by current user and by root to be sure.

@moses-palmer
Copy link
Owner

Perhaps the following script would suffice?

import pynput, time

time.sleep(5)
pynput.keyboard.Controller().type('абв')

Run the script and quickly select the xev window.

@Maboroshy
Copy link
Author

Maboroshy commented Nov 29, 2019

For pynput.keyboard.Controller().type('абв') I get:

output KeyPress event, serial 49, synthetic YES, window 0x5600001, root 0x72b, subw 0x0, time 0, (0,0), root:(0,0), state 0x0, keycode 8 (keysym 0x0, NoSymbol), same_screen NO, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False

KeyRelease event, serial 58, synthetic YES, window 0x5600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 8 (keysym 0x0, NoSymbol), same_screen NO,
XLookupString gives 0 bytes:
XFilterEvent returns: False

KeyPress event, serial 67, synthetic YES, window 0x5600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 8 (keysym 0x0, NoSymbol), same_screen NO,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyRelease event, serial 76, synthetic YES, window 0x5600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 8 (keysym 0x0, NoSymbol), same_screen NO,
XLookupString gives 0 bytes:
XFilterEvent returns: False

KeyPress event, serial 85, synthetic YES, window 0x5600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 8 (keysym 0x0, NoSymbol), same_screen NO,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyRelease event, serial 94, synthetic YES, window 0x5600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 8 (keysym 0x0, NoSymbol), same_screen NO,
XLookupString gives 0 bytes:
XFilterEvent returns: False

For pynput.keyboard.Controller().type('abc') I get:

output KeyPress event, serial 40, synthetic YES, window 0x4600001, root 0x72b, subw 0x0, time 0, (0,0), root:(0,0), state 0x0, keycode 38 (keysym 0x61, a), same_screen NO, XLookupString gives 1 bytes: (61) "a" XmbLookupString gives 1 bytes: (61) "a" XFilterEvent returns: False

KeyRelease event, serial 40, synthetic YES, window 0x4600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 38 (keysym 0x61, a), same_screen NO,
XLookupString gives 1 bytes: (61) "a"
XFilterEvent returns: False

KeyPress event, serial 40, synthetic YES, window 0x4600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 56 (keysym 0x62, b), same_screen NO,
XLookupString gives 1 bytes: (62) "b"
XmbLookupString gives 1 bytes: (62) "b"
XFilterEvent returns: False

KeyRelease event, serial 40, synthetic YES, window 0x4600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 56 (keysym 0x62, b), same_screen NO,
XLookupString gives 1 bytes: (62) "b"
XFilterEvent returns: False

KeyPress event, serial 40, synthetic YES, window 0x4600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 54 (keysym 0x63, c), same_screen NO,
XLookupString gives 1 bytes: (63) "c"
XmbLookupString gives 1 bytes: (63) "c"
XFilterEvent returns: False

KeyRelease event, serial 40, synthetic YES, window 0x4600001,
root 0x72b, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 54 (keysym 0x63, c), same_screen NO,
XLookupString gives 1 bytes: (63) "c"
XFilterEvent returns: False

@fish-dd
Copy link

fish-dd commented Apr 16, 2024

Found out it crashes when trying to type("д") (Cyrillic d) meanwhile it doesn't crash on many other Cyrillic symbols. Sounds bad because this is only solution working with Embedded Python.

@SpecialCharacter
Copy link

Is your encoding set to Unicode or to ISO-whatever?

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

No branches or pull requests

4 participants