forked from samuelkimasu/ProjectParagon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyPressModule.py
More file actions
41 lines (30 loc) · 794 Bytes
/
KeyPressModule.py
File metadata and controls
41 lines (30 loc) · 794 Bytes
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
36
37
38
39
40
41
import pygame
def init():
pygame.init()
win = pygame.display.set_mode((400, 400))
pygame.display.set_caption("Control Window")
def getKey(keyName):
ans = False
for eve in pygame.event.get(): pass
keyInput = pygame.key.get_pressed()
myKey = getattr(pygame, 'K_{}'.format(keyName))
if keyInput[myKey]:
ans = True
pygame.display.update()
return ans
def main():
if getKey("LEFT"):
print("Left Key Pressed")
elif getKey("RIGHT"):
print("Right Key Pressed")
if getKey("UP"):
print("Up Key Pressed")
if getKey("DOWN"):
print("Down Key Pressed")
if getKey("p"):
pygame.display.quit()
pygame.quit()
if __name__ == '__main__':
init()
while True:
main()