summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2016-11-12 18:39:21 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2016-11-12 18:39:21 (GMT)
commitfb436d15811f5f6916e4beec3fd7e29b6f00c7fc (patch)
treec6395d2299e6182e1d9550ebcf8dc5c068a7ac09
parenta7c872c5c8aa4376ac6c3fb96d13065b6fb954af (diff)
downloadcontroller-keyboard-fb436d15811f5f6916e4beec3fd7e29b6f00c7fc.zip
controller-keyboard-fb436d15811f5f6916e4beec3fd7e29b6f00c7fc.tar.gz
Add screenshot key (F12)
Saves a screenshot to "screenshot.png". The file is overwritten if it already exists.
-rw-r--r--.gitignore1
-rw-r--r--lib/Environment.py11
2 files changed, 12 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index c43cd36..6c28c8e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
2*.pyc 2*.pyc
3*.zip 3*.zip
4ck/ 4ck/
5screenshot.png
diff --git a/lib/Environment.py b/lib/Environment.py
index b460c71..fb37fba 100644
--- a/lib/Environment.py
+++ b/lib/Environment.py
@@ -48,6 +48,8 @@ class EnvironmentController(object):
48 ## KEYDOWN event is 25 miliseconds after the previous. 48 ## KEYDOWN event is 25 miliseconds after the previous.
49 pygame.key.set_repeat(500, 25) 49 pygame.key.set_repeat(500, 25)
50 50
51 self.take_screenshot = False
52
51 #self.controller.handler.dump_bindings() 53 #self.controller.handler.dump_bindings()
52 54
53 def update(self): 55 def update(self):
@@ -62,6 +64,11 @@ class EnvironmentController(object):
62 self.hud.set_text(HudLocs.TOPRIGHT, str(math.floor(self.clock.get_fps()))) 64 self.hud.set_text(HudLocs.TOPRIGHT, str(math.floor(self.clock.get_fps())))
63 self.hud.draw(screen) 65 self.hud.draw(screen)
64 66
67 if self.take_screenshot:
68 self.take_screenshot = False
69 pygame.image.save(screen, 'screenshot.png')
70 print("screenshot taken")
71
65 def load_layout(self, layout_file): 72 def load_layout(self, layout_file):
66 pass 73 pass
67 74
@@ -157,6 +164,10 @@ class EnvironmentController(object):
157 self.keyboard_handler.add_keyup_handle(pygame.K_LSHIFT, self.type_shift, args=(False)) 164 self.keyboard_handler.add_keyup_handle(pygame.K_LSHIFT, self.type_shift, args=(False))
158 self.keyboard_handler.add_keyup_handle(pygame.K_RSHIFT, self.type_shift, args=(False)) 165 self.keyboard_handler.add_keyup_handle(pygame.K_RSHIFT, self.type_shift, args=(False))
159 166
167 self.keyboard_handler.add_keydown_handle(pygame.K_F12, self.activate_screenshot, args=())
168
169 def activate_screenshot(self, key):
170 self.take_screenshot = True
160 171
161 def set_joystick_buttons(self): 172 def set_joystick_buttons(self):
162 self.controller.handler.add_joydown_handle("0", self.button_press, args=('a')) 173 self.controller.handler.add_joydown_handle("0", self.button_press, args=('a'))