moses-palmer / pynput

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

Global key detection issue ! #470

Closed captain-majid closed 2 years ago

captain-majid commented 2 years ago

I'm trying to assign a keyboard shortcut to exit a script (bc ctrl+c doesn't work)..

It uses ThreadPoolExecutor to run threads, so I tried to assign a keyboard shortcut to exit the script, used both:

import keyboard
from pynput import keyboard

... When I press the hotkey the script exit successfully, but when running 2 instances of the script using any command-line tool (I'm using Cmder, but happens with anything), the 2 scripts exit, not the1 I pressed the hotkey in it !

moses-palmer commented 2 years ago

Thank you for your report.

The code sample you provided appears to be mostly empty, so I can only guess what is wrong. However, when you press a hotkey, all scripts using that hotkey will be notified, so what you describe is the expected behaviour. Perhaps you should try to look into what is preventing your script from terminating upon SIGINT? Note that if you are running on Windows, the correct key combination is ctrl+break.

I will close this issue as I do no think it is caused by a bug in this library. If you think otherwise, please reopen.