boppreh / keyboard

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

_hooks dict is not cleared on unhook_all #615

Open salahxgamer opened 1 year ago

salahxgamer commented 1 year ago

i've been playing with the library for solid hours, and i noticed a possible bug when browsing the source code, the _hooks dict where are the remove handlers are stored is not being cleared after calling keyboard.unhook_all() and i think it should, or else according to what i experimented with it'll build in memory to a huge object depending on the app, and makes things slower. To replicate :

for i in range(100) :
    keyboard.hook(print)
print(keyboard._hooks) # prints 100
keyboard.unhook_all()
print(keyboard._hooks) # still 100

a simple fix would be to add _hooks.clear() inside unhook_all() if i'm wrong i'd appreciate any explanation