1

I am facing a problem here that I am not able to find the solution obviously. I have some code (I will append it at the end) that when a combo of keys is pressed it executes some code. As I explain on title, I am doing this with pynput.keyboard, but even when CMD is not in focus, when I am pressing CTRL + S ( the combo in script is E + S ) it seems the script executes what E + S is programmed for. Also when I am pressing CTRL + C, I get an error from clipboard_monitor library (it has nothing to do with the current question), instead of just "os._exit(0)" as it is instructed in "try - except" (when E + Q is pressed the program exits as it is supposed to). Finally, I append the libraries I am using. If you are in need of any other part of the code let me know. Any ideas?

Cheers

import clipboard_monitor, os, shutil, sys, subprocess
from time import sleep as Freeze
from tqdm import tqdm
from pynput import keyboard
from threading import Thread
from urllib.error import URLError, HTTPError
from urllib.request import urlretrieve as DL

def poweron(self):
            try:
                with keyboard.GlobalHotKeys({
                    'e+s': self.execute,
                    'e+c': self.showlst,
                    'e+x': self.clrlst,
                    'e+z': self.clrdir,
                    'e+q': self.quit}) as q:
                    q.join()
            except KeyboardInterrupt:
                os._exit(0)
            else:
                pass
Zuss
  • 59
  • 7

1 Answers1

0

For some reason that I am not able to find out, keyboard from pynput listen to some keys separate from the combination and executes functions.

Finally the solution I found is using module "keyboard" and it works like a charm.

import keyboard as KB

class URL2FHDimage():
    def __init__(self):
    -----

    def showlst(self):
    -----

    def clrlst(self):
    -----

    def clrdir(self):
    -----

    def quit(self):
    -----

    def execute(self):
    -----

run = URL2FHDimage()
KB.add_hotkey("e+s", run.execute)
KB.add_hotkey("e+f", run.showlst)
KB.add_hotkey("e+c", run.clrlst)
KB.add_hotkey("e+z", run.clrdir)
KB.add_hotkey("e+q", run.quit)
Zuss
  • 59
  • 7