-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (40 loc) · 1.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import keyboard
import pyautogui
import pystray
from pystray import MenuItem as item
from PIL import Image
import sys
import os
def on_key_pressed(event):
"""
Handling key combinations
"""
if event.event_type == keyboard.KEY_DOWN:
if event.name.isdigit() and event.name != '0' and keyboard.is_pressed('f'):
# Get the number of the F key that needs to be emulated
f_key = 'f' + event.name
pyautogui.press(f_key)
elif event.name == '0' and keyboard.is_pressed('alt'):
pyautogui.press('f10')
elif event.name == '1' and keyboard.is_pressed('alt'):
pyautogui.press('f11')
elif event.name == '2' and keyboard.is_pressed('alt'):
pyautogui.press('f12')
def create_tray_icon():
"""
Create icon for system tray
"""
icon_path = os.path.join(sys._MEIPASS, "icon.png") if hasattr(sys, '_MEIPASS') else "icon.png"
icon = Image.open(icon_path)
menu = (item('Exit', quit_application),)
return pystray.Icon("name", icon, "DamnFn", menu)
def quit_application(icon):
"""
Exit app
"""
icon.stop()
# Set up a keypress event handler
keyboard.on_press(on_key_pressed)
# Create and run icon in system tray
tray = create_tray_icon()
tray.run()