moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.79k stars 248 forks source link

Strange behavior of AltGr in Word #358

Closed SpecialCharacter closed 3 years ago

SpecialCharacter commented 3 years ago

When I detect AltGr+0 [ = } ], I want to delete } and replace it with some other character. It works fine in python, but in a Word document, the } stays, no matter how many backspaces I sent. Texteditor and Thunderbolt work fine. Anybody has the same issue? (Windows 10)

SpecialCharacter commented 3 years ago

I changed the heading because the AltGr works in Word, but it affects the delete-and-replace actions after the character is typed.

SpecialCharacter commented 3 years ago

For example, I write kbc.type('y'... and instead of writing y in Word, the program executes "key 89" (have not identified it), spawns a popup and inserts y into the popup. Almost like I pressed the Alt key.

I know that AltGr is disintegrated into ctrl_l and alt_r in Windows, but I did not expect this behaviour. Is there a way around this?

SpecialCharacter commented 3 years ago

OK, I deactivated ctrl_l and alt_r before proceeding with the character processing: kbc.release(Key.ctrl_l) kbc.release(Key.alt_r) Not an elegant solution, but at least my code works like I intended...

I am open for a more elegant solution!

moses-palmer commented 3 years ago

Thank you for your report.

This library is unfortunately a rather leaky abstraction over four different systems. Especially Windows is keen on maintaining internal state for the keyboard in the kernel, so things like this are bound to happen. It is unfortunately not feasible to continually synchronise this state either.