def main():
elements = [140, 150, 160, 170, 180, 185, 190, 200, 225, 250, 275, 300, 325, 350, 400, 450, 500, 550] # Все масштабы карт в игре
current_selection = -1
n_seconds = 2 # Время бездействия в секундах
t = None
ctrl_pressed = False
def on_scroll(x, y, dx, dy):
nonlocal ctrl_pressed
nonlocal current_selection
nonlocal t
if ctrl_pressed:
if dy > 0:
current_selection += 1
current_selection %= len(elements) # Зацикливание списка
print(f"Текущий выбранный масштаб: {elements[current_selection]}")
selection_data = {"selection": elements[current_selection]}
state_queue.put(selection_data)
if t is not None:
t.cancel()
t = Timer(n_seconds, process_selection, [elements[current_selection]])
t.start()
else:
t = Timer(n_seconds, process_selection, [elements[current_selection]])
t.start()
else:
current_selection -= 1
current_selection %= len(elements) # Зацикливание списка
print(f"Текущий выбранный масштаб: {elements[current_selection]}")
selection_data = {"selection": elements[current_selection]}
state_queue.put(selection_data)
if t is not None:
t.cancel()
t = Timer(n_seconds, process_selection, [elements[current_selection]])
t.start()
print(ctrl_pressed)
else:
t = Timer(n_seconds, process_selection, [elements[current_selection]])
t.start()
print(ctrl_pressed)
def on_press(key):
nonlocal ctrl_pressed
if key == Key.ctrl_l:
ctrl_pressed = True
def on_release(key):
nonlocal ctrl_pressed
if key == Key.ctrl_l:
ctrl_pressed = False
with Listener(on_scroll=on_scroll) as listener, Key_Listener(on_press=on_press,
on_release=on_release) as key_listener:
listener.join()
key_listener.join()
def main():
elements = [140, 150, 160, 170, 180, 185, 190, 200, 225, 250, 275, 300, 325, 350, 400, 450, 500, 550]
current_selection = -1
n_seconds = 2
t = None
ctrl_pressed = False
# Функция для горячей клавиши Ctrl + Alt + H
def on_activate_hotkey():
nonlocal current_selection, t
print("Комбинация Ctrl + Alt + H нажата!")
# Обработка скролла мыши
def on_scroll(x, y, dx, dy):
nonlocal ctrl_pressed, current_selection, t
if ctrl_pressed:
if dy > 0:
current_selection = (current_selection + 1) % len(elements)
else:
current_selection = (current_selection - 1) % len(elements)
print(f"Текущий выбранный масштаб: {elements[current_selection]}")
selection_data = {"selection": elements[current_selection]}
state_queue.put(selection_data)
if t is not None:
t.cancel()
t = Timer(n_seconds, process_selection, [elements[current_selection]])
t.start()
# Обработка нажатий клавиш для Ctrl
def on_press(key):
nonlocal ctrl_pressed
try:
if key == keyboard.Key.ctrl_l:
ctrl_pressed = True
except AttributeError:
pass
# Обработка отпусканий клавиш для Ctrl
def on_release(key):
nonlocal ctrl_pressed
try:
if key == keyboard.Key.ctrl_l:
ctrl_pressed = False
except AttributeError:
pass
# Запуск слушателя мыши
mouse_listener = mouse.Listener(on_scroll=on_scroll)
mouse_listener.start()
# Запуск слушателя клавиатуры с GlobalHotKeys и обработкой Ctrl
with keyboard.Listener(on_press=on_press, on_release=on_release) as key_listener, \
keyboard.GlobalHotKeys({'<ctrl>+<alt>+h': on_activate_hotkey}) as hotkey_listener:
key_listener.join()
hotkey_listener.join()