pynput icon indicating copy to clipboard operation
pynput copied to clipboard

"type" changes its behaviour to ignore the keyboard layout.

Open papoteur-mga opened this issue 3 years ago • 4 comments

The first words sent with the type function is OK, but after I used press(Key.backspace) release(Key.backspace) the following words are typed without applying the keyboard layout. This is not the case if I use type function without the backspace sequence.

Linux Mageia 7, pynput 1.7.3 from pypi

To Reproduce

#!/usr/bin/env python3
from pynput.keyboard import Controller, Key
import time

c = Controller()
time.sleep(2)
c.type("1maman ")
c.press(Key.backspace)
time.sleep(0.01)
c.release(Key.backspace)

time.sleep(.5)
c.type("2maman")

c.press(Key.backspace)
time.sleep(0.01)
c.release(Key.backspace)
time.sleep(.5)
c.type("3maman")

time.sleep(.5)
c.type("4maman")

c.press(Key.backspace)
time.sleep(0.01)
c.release(Key.backspace)
time.sleep(.5)
c.type("5maman")

Result: 1maman@;q;q#;q;qn$;q;q%;q;qn the first word is OK, but the following are as they was typed on my French keyboard but rendered with the US keyboard layout.

papoteur-mga avatar Jun 08 '21 19:06 papoteur-mga

Thank you for your report.

I have tested your code sample on Ubuntu 21.04 under GNOME/Wayland in a Chrome window to ensure the X backend is used, and unfortunately I cannot reproduce.

I had a quick glance at the Mageia homepage to attempt to deduce what desktop environment is in use, but it appears to support a large selection. Could it be that---I do realise that this seems very unlikely given the input---one of the combinations triggers a keyboard layout change? Does your desktop environment support displaying the currently active layout? Is only pynput.Keyboard.type affected, or do normal keypresses also switch layouts?

moses-palmer avatar Jun 30 '21 15:06 moses-palmer

Hello, I use LXQt 0.14.1, thus no wayland but Xorg. Only pynput.Keyboard.type is affected. The locale layout is still used. I presume that this has something to do with Xlib or Xorg itself.

papoteur-mga avatar Jun 30 '21 16:06 papoteur-mga

I should add that when I launch before: setkbdmap fr, the output is always correct. I consider this is a workaround, because not everybody accept to have to launch this command which can overwrite some personal configurations.

papoteur-mga avatar Jul 02 '21 10:07 papoteur-mga

Is only pynput.Keyboard.type affected, or do normal keypresses also switch layouts?

I didn't understand well the question. After wider tests, function press is also affected by the bad behaviour. I obtain Q instead of A with press/release.

papoteur-mga avatar Jul 04 '21 17:07 papoteur-mga