-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKeybordControllerClass.py
50 lines (43 loc) · 1.31 KB
/
KeybordControllerClass.py
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
42
43
44
45
46
47
48
49
50
import pygame
class KeybordControllerClass:
def __init__(self):
pygame.init()
pygame.font.init() # you have to call this at the start,
self.font_size = 30
self.my_font = pygame.font.SysFont('Comic Sans MS', self.font_size)
self.win = pygame.display.set_mode((400,400))
def drawWarning(self, value, text=[]):
# Initialing Color
self.win.fill(pygame.Color('black'))
if value == True:
color = (255, 0, 0)
else:
color = (0, 255, 0)
# Drawing Rectangle
pygame.draw.rect(self.win, color, pygame.Rect(0, 200, 400, 200))
yy = 0
for tt in text:
text_surface = self.my_font.render(tt, False, (255, 255, 255))
self.win.blit(text_surface, (0, yy))
yy += self.font_size + 1
#pygame.display.flip()
pygame.display.update()
def getKey(self, keyPressed):
ans = False
for eve in pygame.event.get(): pass
keyInput = pygame.key.get_pressed()
myKey = getattr(pygame, 'K_{}'.format(keyPressed))
if keyInput[myKey]:
ans = True
pygame.display.update()
return ans
"""
def main():
print(getKey("a"))
"""
"""
if __name__ == '__main__':
init()
while True:
main()
"""