boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.77k stars 433 forks source link

Using a numerical string also hooks the scan code #392

Open FlamingKetchup opened 3 years ago

FlamingKetchup commented 3 years ago

Using a numerical string i.e. "4" or even "num 4" with add_hotkey also hooks the scan code (In this case, left arrow). If you have hook both the number and the key with corresponding scan code, pressing the latter will also run the former.

import keyboard

keyboard.add_hotkey("4", print, args=["Four was pressed"])
keyboard.add_hotkey("left", print, args=["Left was pressed"])
keyboard.wait()

Output when pressing 4 (expected behavior):

Four was pressed

Output when pressing left arrow:

Four was pressed
Left was pressed
FlamingKetchup commented 3 years ago

This seems to be an issue with adding a hotkey for the numerical string. For example, removing keyboard.add_hotkey("left", print, args=["Left was pressed"]) has the same issue of outputting Four was pressed when pressing left arrow.

zizihe113-network commented 1 year ago

Yes, I used the function keyboard.press('left') to press "left arrow".But in fact,it pressed "num 4" ranther than the arrow.