-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyPressModule.py
More file actions
35 lines (29 loc) · 1.07 KB
/
Copy pathKeyPressModule.py
File metadata and controls
35 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pygame
## This is what opens up the console window
def init():
pygame.init()
win= pygame.display.set_mode((400, 400))
def quit():
pygame.quit()
## function calling from a different script in keyName is a paramiter that will be filled in the other script it could be the up arrow, a, d, e whatever
def getKey(keyName):
## by default the value for getKey will be false if such as when the button is not selected, but will be true when a button is pressed
ans = False
## for loop that checks even keys but not necisarly doing anything with tem
for eve in pygame.event.get(): pass
## to check true or false we need a particular format which is the 'K_{}'.format(keyName)
keyInput = pygame.key.get_pressed()
myKey = getattr(pygame,'K_{}'.format(keyName))
# print('K_{}'.format(keyName))
##
if keyInput[myKey]:
ans = True
pygame.display.update()
return ans
def main():
if getKey("LEFT"):
print("Left key pressed")
if getKey("RIGHT"):
print("Right key Pressed")
if __name__ == "__main__":
init()