Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
exapunks-hackmatch-bot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
exapunks-hackmatch-bot
Commits
05436333
Commit
05436333
authored
Apr 06, 2020
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Take screenshot when S is pressed while bot is playing
parent
b62da615
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletion
+29
-1
bot.py
bot.py
+17
-1
interaction.py
interaction.py
+12
-0
No files found.
bot.py
View file @
05436333
#!/usr/bin/env python3
#!/usr/bin/env python3
import
os
import
time
import
time
from
itertools
import
count
from
strategy
import
State
,
moves_to_keys
from
strategy
import
State
,
moves_to_keys
from
interaction
import
get_exapunks_window
,
focus_window
,
\
from
interaction
import
get_exapunks_window
,
focus_window
,
\
screenshot_board
,
press_keys
screenshot_board
,
press_keys
,
listen_keys
def
save_screenshot
(
win
):
board
=
screenshot_board
(
win
).
convert
(
'RGB'
)
os
.
makedirs
(
'screens'
,
exist_ok
=
True
)
for
i
in
count
(
1
):
path
=
'screens/board%d.png'
%
i
if
not
os
.
path
.
exists
(
path
):
print
(
'save screenshot in'
,
path
)
board
.
save
(
path
)
break
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
win
=
get_exapunks_window
()
win
=
get_exapunks_window
()
focus_window
(
win
)
focus_window
(
win
)
listen_keys
({
's'
:
lambda
:
save_screenshot
(
win
)})
prev_score
=
None
prev_score
=
None
while
True
:
while
True
:
...
...
interaction.py
View file @
05436333
...
@@ -53,6 +53,7 @@ def screenshot_board(window):
...
@@ -53,6 +53,7 @@ def screenshot_board(window):
def
press_keys
(
window
,
keys
):
def
press_keys
(
window
,
keys
):
assert
disp
.
has_extension
(
'XTEST'
)
for
key
in
keys
:
for
key
in
keys
:
keysym
=
XK
.
string_to_keysym
(
key
)
keysym
=
XK
.
string_to_keysym
(
key
)
keycode
=
disp
.
keysym_to_keycode
(
keysym
)
keycode
=
disp
.
keysym_to_keycode
(
keysym
)
...
@@ -66,6 +67,17 @@ def press_keys(window, keys):
...
@@ -66,6 +67,17 @@ def press_keys(window, keys):
time
.
sleep
(
KEY_DELAY
)
time
.
sleep
(
KEY_DELAY
)
def
listen_keys
(
handlers
):
from
pynput
import
keyboard
def
handler
(
keycode
):
key
=
str
(
keycode
).
replace
(
'
\
'
'
,
''
)
if
key
in
handlers
:
handlers
[
key
]()
keyboard
.
Listener
(
on_release
=
handler
).
start
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
win
=
get_exapunks_window
()
win
=
get_exapunks_window
()
win
.
raise_window
()
win
.
raise_window
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment