aboutsummaryrefslogtreecommitdiff
path: root/inputs/PygameInput.py
diff options
context:
space:
mode:
Diffstat (limited to 'inputs/PygameInput.py')
-rw-r--r--inputs/PygameInput.py35
1 files changed, 22 insertions, 13 deletions
diff --git a/inputs/PygameInput.py b/inputs/PygameInput.py
index 27b82b0..399a77e 100644
--- a/inputs/PygameInput.py
+++ b/inputs/PygameInput.py
@@ -6,18 +6,27 @@ from pygame.locals import *
#This class processes input from an already running pygame instance and passes
#it to the parent. This class requires an already running pygame instance.
class PygameInput(Input):
+ """PygameInput is an input tied to the PygameDisplay. Specify:
+ <FollowMouse>True</FollowMouse> to receive an input every frame specifying the current mouse
+ position.
+ <Keyboard>True</Keyboard> to grab keystrokes
+ <Clicks>True</Clicks> to grab clicks.
+
+ NB: If follow mouse is enabled, PygameInput will not return mouse and keypresses. You can, however,
+ instantiate other PygameInputs in the XML that will capture mouse and keypresses."""
def sensingLoop(self):
- #try:
- if self['FollowMouse']:
- self.respond({Strings.LOCATION: pygame.mouse.get_pos()})
- return
- for event in pygame.event.get():
- if event.type is KEYDOWN:
- if event.key == 27:
- self.die()
- self.respond({Strings.LOCATION: (5,5),'Key': event.key})
- if event.type is MOUSEBUTTONDOWN:
+ if self['FollowMouse']:
+ self.respond({Strings.LOCATION: pygame.mouse.get_pos()})
+ return
+ for event in pygame.event.get():
+ if event.type is KEYDOWN:
+ if event.key == 27:
+ self.die()
+ if self['Keyboard']:
+ self.respond({'Key': event.key})
+ return
+ else:
+ pygame.event.post(event)
+ if event.type is MOUSEBUTTONDOWN:
+ if self['Clicks']:
self.respond({Strings.LOCATION: pygame.mouse.get_pos()})
- #except:
- #raise Exception('Pygame not initialized. Pygame must be \
- #initialized.')