forked from JauriaStudios/soulmaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.py
31 lines (22 loc) · 847 Bytes
/
input.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
# -*- coding: utf-8 -*-
from collections import defaultdict
class Input:
def __init__(self):
self.held_keys = defaultdict(bool)
self.pressed_keys = defaultdict(bool)
self.released_keys = defaultdict(bool)
def begin_new_frame(self):
self.pressed_keys.clear()
self.released_keys.clear()
def key_down_event(self, event):
self.pressed_keys[event.key.keysym.sym] = True
self.held_keys[event.key.keysym.sym] = True
def key_up_event(self, event):
self.released_keys[event.key.keysym.sym] = True
self.held_keys[event.key.keysym.sym] = False
def was_key_pressed(self, key):
return self.pressed_keys[key]
def was_key_released(self, key):
return self.released_keys[key]
def is_key_held(self, key):
return self.held_keys[key]