Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exapunks-hackmatch-bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
exapunks-hackmatch-bot
Commits
05436333
Commit
05436333
authored
5 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Take screenshot when S is pressed while bot is playing
parent
b62da615
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bot.py
+17
-1
17 additions, 1 deletion
bot.py
interaction.py
+12
-0
12 additions, 0 deletions
interaction.py
with
29 additions
and
1 deletion
bot.py
+
17
−
1
View file @
05436333
#!/usr/bin/env python3
import
os
import
time
from
itertools
import
count
from
strategy
import
State
,
moves_to_keys
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__
'
:
win
=
get_exapunks_window
()
focus_window
(
win
)
listen_keys
({
'
s
'
:
lambda
:
save_screenshot
(
win
)})
prev_score
=
None
while
True
:
...
...
This diff is collapsed.
Click to expand it.
interaction.py
+
12
−
0
View file @
05436333
...
...
@@ -53,6 +53,7 @@ def screenshot_board(window):
def
press_keys
(
window
,
keys
):
assert
disp
.
has_extension
(
'
XTEST
'
)
for
key
in
keys
:
keysym
=
XK
.
string_to_keysym
(
key
)
keycode
=
disp
.
keysym_to_keycode
(
keysym
)
...
...
@@ -66,6 +67,17 @@ def press_keys(window, keys):
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__
'
:
win
=
get_exapunks_window
()
win
.
raise_window
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment