-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.py
More file actions
38 lines (27 loc) · 1.21 KB
/
Copy pathInputHandler.py
File metadata and controls
38 lines (27 loc) · 1.21 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
36
37
38
import pygame
from time import time
class InputEvents:
def __init__(self):
self.quit = False
self.MouseClickDown = [False, False, False]
self.MouseClickUp = [False, False, False]
self.MouseClickTiming = [None, None, None]
self.WASDKeys = [pygame.K_w, pygame.K_a, pygame.K_s, pygame.K_d]
self.WASDHold = [False, False, False, False]
def reset(self):
self.MouseClickDown = [False, False, False]
self.MouseClickUp = [False, False, False]
def poll(self):
self.reset()
keysPressed = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit = True
if event.type == pygame.MOUSEBUTTONDOWN and 1 <= event.button <= 3:
self.MouseClickDown[event.button-1] = True
self.MouseClickTiming[event.button-1] = time()
elif event.type == pygame.MOUSEBUTTONUP and 1 <= event.button <= 3:
self.MouseClickUp[event.button-1] = True
self.MouseClickTiming[event.button-1] = None
for i, key in enumerate(self.WASDKeys):
self.WASDHold[i] = keysPressed[key]