У меня есть вот такой код
from pynput.keyboard import Key, KeyCode, Listener
from pynput.mouse import Button, Controller
import sys, os, ctypes
import pyscreenshot as ImageGrab
# закончить код
def end_fun():
sys.exit()
def start_mouse():
print('dddd')
def save_image():
print('ssss')
im = ImageGrab.grab()
# Код для горячих клавищ
combination_to_function = {
frozenset([KeyCode(vk=49)]): end_fun,
frozenset([KeyCode(vk=50)]): start_mouse,
frozenset([KeyCode(vk=53)]): save_image,
}
# The currently pressed keys (initially empty)
pressed_vks = set()
def get_vk(key):
return key.vk if hasattr(key, 'vk') else key.value.vk
def is_combination_pressed(combination):
return all([get_vk(key) in pressed_vks for key in combination])
def on_press(key):
vk = get_vk(key) # Get the key's vk
print(':vk =', vk, ':key =', key)
pressed_vks.add(vk) # Add it to the set of currently pressed keys
for combination in combination_to_function: # Loop through each combination
if is_combination_pressed(combination): # Check if all keys in the combination are pressed
combination_to_function[combination]() # If so, execute the function
def on_release(key):
vk = get_vk(key) # Get the key's vk
pressed_vks.remove(vk) # Remove it from the set of currently pressed keys
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
И когда я добавляю строку
im = ImageGrab.grab()
И нажимаю "2" "5" "2"
То вовремя повторного нажатия "2" запускается функция start_mouse и save_image
Как исправить этот баг?