moses-palmer / pynput

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

Get the original pressed key #591

Open tisonkun opened 6 months ago

tisonkun commented 6 months ago

Reported at https://github.com/GreptimeTeam/demo-scene/issues/2.

More simpler repro: Shift + 3 will result in Key.shfit + # instead of Key.shfit + 3.

Is it possible we get exactly the key pressed? Or this is a limitation of sys API or hardware API.

I noticed that https://github.com/LaunchMenu/node-global-key-listener can get properly 3,true,LEFT SHIFT,true for Shift + 3.

moses-palmer commented 5 months ago

Thank you for your report.

On Windows, the keyboard listener explicitly includes the currently active modifiers when translating the keyboard event (represented by KBDLLHOOKSTRUCT) into a character representation (see here).

It would certainly be possible to perform an additional lookup without any modifiers active, but I would need to consider a reasonable way to integrate this, and implement similar functionality for the other platforms as well.