-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhanlder.py
134 lines (104 loc) · 3.33 KB
/
hanlder.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
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
from tkinter import *
from random import randint as rand
from pynput.mouse import Listener as mouseListener, Button as Butt
from keyboard import press_and_release
wList = []
kList = []
randomizeFlag = False
mainThreadFlag = True
window = Tk()
window.title('Block Randomizer')
def onClick(clickx, clicky, button, pressed):
if pressed:
if button == Butt.right and randomizeFlag:
maxW = wList[-1]
num = rand(1, maxW)
# print(num)
for i, w in enumerate(wList):
if num <= w:
press_and_release(kList[i])
# print(f'{kList[i]} key has been pressed')
break
# def main():
# global randomizeFlag
# print('mainThread started')
# while mainThreadFlag:
# if randomizeFlag:
# print('running')
# sleep(0.5)
# print('mainThread stopped')
def setWeight():
global wList
try:
prevW = (wList[-1] if len(wList) > 0 else 0)
wList.append(int(weightInput.get()) + prevW)
except ValueError:
return 0
weightListLab['text'] = f'WeightList:{wList}'
def popWeight():
global wList
try:
wList.pop(-1)
except IndexError:
return 0
weightListLab['text'] = f'WeightList:{wList}'
def setKey():
global kList
kList.append(keyInput.get())
keyListLab['text'] = f'KeyList:{kList}'
def popKey():
global kList
try:
kList.pop(-1)
except IndexError:
return 0
keyListLab['text'] = f'WeightList:{kList}'
def startThread():
global randomizeFlag
# GUI
if len(kList) == len(wList) and len(kList) > 0 and len(kList) > 0:
randomizeFlag = True
startButt['state'] = DISABLED
stopButt['state'] = ACTIVE
setWeightButt['state'] = DISABLED
setKeyButt['state'] = DISABLED
removeWeightButt['state'] = DISABLED
removeKeyButt['state'] = DISABLED
else:
return 0
def stopThread():
global randomizeFlag
randomizeFlag = False
startButt['state'] = ACTIVE
stopButt['state'] = DISABLED
setWeightButt['state'] = ACTIVE
setKeyButt['state'] = ACTIVE
removeWeightButt['state'] = ACTIVE
removeKeyButt['state'] = ACTIVE
weightListLab = Label(window, text=f'WeightList:{wList}')
weightInput = Entry(window, width=3)
setWeightButt = Button(window, text='Set', command=setWeight)
removeWeightButt = Button(window, text='Remove', command=popWeight)
keyListLab = Label(window, text=f'KeyList:{kList}')
keyInput = Entry(window, width=3)
setKeyButt = Button(window, text='Set', command=setKey)
removeKeyButt = Button(window, text='Remove', command=popKey)
startButt = Button(window, text='Start', command=startThread, state=ACTIVE)
stopButt = Button(window, text='Stop', command=stopThread, state=DISABLED)
window.geometry('320x240')
# window.config(background='gray')
weightListLab.grid(row=0, column=0)
weightInput.grid(row=0, column=1)
setWeightButt.grid(row=0, column=2)
removeWeightButt.grid(row=0, column=3)
keyListLab.grid(row=1, column=0)
keyInput.grid(row=1, column=1)
setKeyButt.grid(row=1, column=2)
removeKeyButt.grid(row=1, column=3)
startButt.grid(row=3, column=0)
stopButt.grid(row=3, column=1)
# mainThread = Thread(target=main)
mouseListener = mouseListener(on_click=onClick)
mouseListener.start()
# mainThread.start()
window.mainloop()