Changeset 35

User picture

Author: sidke

(2008/12/06 16:28) Over 3 years ago


  

Affected files

Updated portfolio/code/Python/controller.py Download diff

3435
11
#our class to act as a buffer for keystrokes
11
#our class to act as a buffer for keystrokes
12
class Keyboard:
12
class Keyboard:
13
    def __init__(self):
13
    def __init__(self):
14
        self.keys = {}                  #initialize our key array
14
        self.keys = {}                  #initialize our key dict
15
15
16
    def press(self, button):            #set a button as pressed
16
    def press(self, button):            #set a button as pressed
17
        self.keys[button] = 1
17
        self.keys[button] = 1
...
...
26
26
27
    def is_pressed(self, button):       #check to see if a key is pressed...
27
    def is_pressed(self, button):       #check to see if a key is pressed...
28
        try:                            #try to see if the key has been put into the key array,  
28
        try:                            #try to see if the key has been put into the key array,  
29
            if self.keys[button] != -1: #because if it doesn't we error out.
29
            if self.keys[button] != -1: #because if it hasn't we error out.
30
                return True
30
                return True
31
        except:
31
        except:
32
            self.keys[button] = -1      #if the key isn't in our array, put it there as 'unpressed'
32
            self.keys[button] = -1      #if the key isn't in our array, put it there as 'unpressed'