-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeybindLogic.py
48 lines (38 loc) · 1.81 KB
/
KeybindLogic.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
from pynput import keyboard
from pynput.keyboard import Key, Listener
import os
import sys
from AppLaunch import *
openTheWindow=False #variable for when to launch the window
defaultKeys=[Key.cmd, Key.ctrl_l, Key.alt_l]
customKeys=[Key.cmd, Key.ctrl_l, Key.alt_l] #TODO-make custom keys a list saved in the device
areCustomKeysEnabled=False #variable for whether custom keys are enabled or not
pressed={} #declare the list with all the pressed keys-and whether they are set to True or False
print("starting the program") #for debug stuff
def IsKeyPressed(key): #check if key is in in the list, then return it's value to avoid null references
if key in pressed:
return pressed[key]
return False
def AreAllKeysPressed(listToCheck): #returns True if all the keys in the given list were pressed, and False otherwise
for keys in listToCheck:
if not IsKeyPressed(keys):
return False
return True
def OnPress(key): #gets called whenever a key of from the keyboard is pressed
if key not in pressed: #key was never pressed before, add it to the pressed variable
pressed[key] = False
if not pressed[key]: #if the key was not already set to pressed, set it to True
pressed[key] = True
print('Key %s was pressed' % key)
isCustomKeyPressed = AreAllKeysPressed(customKeys)
isDefaultKeyPressed = AreAllKeysPressed(defaultKeys)
isKeybindPressed = isCustomKeyPressed if areCustomKeysEnabled else isDefaultKeyPressed
if isKeybindPressed:
print("open window")
LaunchAppsFromText()
pressed.clear()
def OnRelease(key): #gets called whenever a key from the keyboard is released
pressed[key]=False
print('Key %s released' %key)
with keyboard.Listener(on_press=OnPress, on_release=OnRelease) as listener:
listener.join()