-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfOnlyIWasRightHanded.py
More file actions
154 lines (115 loc) · 4.39 KB
/
IfOnlyIWasRightHanded.py
File metadata and controls
154 lines (115 loc) · 4.39 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!python3
import pathlib, time, threading, os, subprocess, arguments, sys
from pynput.keyboard import Key, Listener
global debug
class Keypress (threading.Thread): #Thread for TypingKey Check
def __init__(self, threadID, name, Super):
threading.Thread.__init__(self)
self.name = name
def run(self):
print("Started " + self.name)
with Listener(on_press = lambda event: KeypressRun(event, Super)) as listener:
listener.join()
print("Exiting " + self.name)
class Cycle (threading.Thread): #Thread for while loop
def __init__(self, threadID, name, StartFile, GameList):
threading.Thread.__init__(self)
self.name = name
def run(self):
print("Started " + self.name)
CycleRun(Timer, TimerValue, StartFile, GameList)
print("Exiting " + self.name)
def CycleRun(Timer, TimerValue, StartFile, GameList):
global WindowName
while True:
Timer -= 1
time.sleep(0.2)
if Timer == 0:
Timer = TimerValue
if StartFile != sh("cat {0}".format(GameList)):
UpdateGameList(GameList, AbPath)
try:
if sh("xdotool getactivewindow getwindowname") != WindowName: #If last known window title is not current update the string
WindowName = sh("xdotool getactivewindow getwindowname")
if debug == True:
print("Window Changed\nNew Window: {0}".format(WindowName))
ChangeLayout(WindowName)
except:
print("Failed to get window name") #If xdotool fails to get the window name is doesnt exit the program
def KeypressRun(key, Super):
global Mode
if key == Key.enter:
if debug == True:
print("Enter Key has been pressed")
if Mode == 2:
Mode = 3
ModeSwitch("GameType")
elif Mode == 3:
Mode = 2
ModeSwitch("Game")
if key == key.cmd_l and Super == 1:
Mode = 1
ModeSwitch("Normal")
def ModeSwitch(mode):
if mode == "Game":
os.system("echo mode 2 switch > /dev/input/ckb1/cmd;")
elif mode == "Normal":
os.system("echo mode 1 switch > /dev/input/ckb1/cmd;")
elif mode == "GameType":
os.system("echo mode 3 switch > /dev/input/ckb1/cmd;")
if debug == True:
print("Mode Switched to: {0}".format(mode))
def UpdateGameList(GameList, AbPath):
global ShebangedList, UnShebangedList
GameList = str(AbPath) + "/GameList.txt" #Look at the current version of the GameList.txt file
f = open(GameList, "r")
ShebangedList, UnShebangedList = [], [] #Clear the prior GameList Arrays
for x in f.read().splitlines(): #Split the GameList file via linebreak
if x.endswith("::"):
ShebangedList += [x[:-2]] #Add game to shebang list if it has a shebang
else:
UnShebangedList += [x] #If a game does not have a shebang add it to the normal list
if debug == True:
print(ShebangedList)
print(UnShebangedList)
def ChangeLayout(WindowName):
global Mode
Layout = 0
for x in ShebangedList:
if x in WindowName: #If shebanged gamename is in the window title
Mode, Layout = 2, 1
ModeSwitch("Game")
for x in UnShebangedList: #If window title in GameList
if x == WindowName:
Mode, Layout = 2, 1
ModeSwitch("Game")
if Layout == 0:
Mode = 1
ModeSwitch("Normal")
def sh(cmd, input=""):
rst = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, input=input.encode("utf-8"))
assert rst.returncode == 0, rst.stderr.decode("utf-8")
return rst.stdout.decode("utf-8")[:-1]
ShebangedList, UnShebangedList = [], []
debug = False
Mode = 1
TimerValue = 4
Timer = 4
WindowName = sh("xdotool getactivewindow getwindowname")
AbPath = pathlib.Path(__file__).parent.resolve()
GameList = str(AbPath) + "/GameList.txt"
StartFile = sh("cat {0}".format(GameList))
if __name__ == "__main__":
UpdateGameList(GameList, AbPath)
print(sys.argv)
if "--debug" in str(sys.argv):
print("Debug mode enabled")
debug = True
if "-ds" in str(sys.argv) or "--DisableSuper" in str(sys.argv):
Super = 0
else:
Super = 1
Keypress = Keypress(1, "Keypress", Super)
Cycle = Cycle(2, "Cycle", StartFile, GameList)
Keypress.start()
Cycle.start()