/
example.py
186 lines (143 loc) · 4.46 KB
/
example.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
"""
A simple example of hooking the keyboard on Linux using pyxhook
Any key pressed prints out the keys values, program terminates when spacebar
is pressed.
"""
from __future__ import print_function
# Libraries we need
import pyxhook
import time
import sys, termios, tty, os, time
import autopy
import os, os.path
try :
os.makedirs('nude')
except FileExistsError as e :
pass
try :
os.makedirs('semi_nude')
except FileExistsError as e :
pass
try :
os.makedirs('animated')
except FileExistsError as e :
pass
try :
os.makedirs('porn')
except FileExistsError as e :
pass
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
button_delay = 0.2
DIR = 'porn'
n_porn = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
DIR = 'semi_nude'
n_semi_nude = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
DIR = 'nude'
n_nude = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
DIR = 'animated'
n_animated = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
print(n_nude , n_semi_nude , n_porn , n_animated)
"""
while True:
char = getch()
if (char == "p"):
print("Stop!")
exit(0)
if (char == "a"):
print("Left pressed")
n_nude += 1
bmp = autopy.bitmap.capture_screen()
bmp.save('nude/nude{}.png'.format(n_nude))
time.sleep(button_delay)
elif (char == "d"):
print("Right pressed")
n_semi_nude += 1
bmp = autopy.bitmap.capture_screen()
bmp.save('semi_nude/semi_nude{}.png'.format(n_semi_nude))
time.sleep(button_delay)
elif (char == "w"):
print("Up pressed")
n_animated += 1
bmp = autopy.bitmap.capture_screen()
bmp.save('animated/animated{}.png'.format(n_animated))
time.sleep(button_delay)
elif (char == "s"):
print("Down pressed")
n_porn += 1
bmp = autopy.bitmap.capture_screen()
bmp.save('porn/porn{}.png'.format(n_porn))
time.sleep(button_delay)
elif (char == "1"):
print("Number 1 pressed")
time.sleep(button_delay)
"""
# This function is called every time a key is presssed
def kbevent(event):
global running
global n_nude
global n_semi_nude
global n_animated
global n_porn
global button_delay
# print key info
#print(event)
# If the ascii value matches spacebar, terminate the while loop
if event.Ascii == 113:
running = False
print('quitting')
elif event.Ascii == 110:
print("Left pressed")
n_nude += 1
bmp = autopy.bitmap.capture_screen()
bmp.save('nude/nude{}.png'.format(n_nude))
time.sleep(button_delay)
elif event.Ascii == 115:
print("Right pressed")
n_semi_nude += 1
bmp = autopy.bitmap.capture_screen()
bmp.save('semi_nude/semi_nude{}.png'.format(n_semi_nude))
time.sleep(button_delay)
elif event.Ascii == 112:
print("up pressed")
n_porn += 1
bmp = autopy.bitmap.capture_screen()
bmp.save('porn/porn{}.png'.format(n_porn))
time.sleep(button_delay)
elif event.Ascii == 97:
print("down pressed")
n_animated += 1
bmp = autopy.bitmap.capture_screen()
bmp.save('animated/animated{}.png'.format(n_animated))
time.sleep(button_delay)
#Create hookmanager
hookman = pyxhook.HookManager()
# Define our callback to fire when a key is pressed down
hookman.KeyDown = kbevent
# Hook the keyboard
hookman.HookKeyboard()
# Start our listener
hookman.start()
# Create a loop to keep the application running
running = True
button_delay = 0.2
DIR = 'porn'
n_porn = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
DIR = 'semi_nude'
n_semi_nude = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
DIR = 'nude'
n_nude = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
DIR = 'animated'
n_animated = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])
#print(n_nude , n_semi_nude , n_porn , n_animated)
while running:
time.sleep(0.1)
# Close the listener when we are done
hookman.cancel()