-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.py
100 lines (76 loc) · 2.1 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import pygame
class Mouse:
pos = (0, 0)
oldstate = (0, 0, 0)
state = (0, 0, 0)
@staticmethod
def update():
Mouse.oldstate = Mouse.state
Mouse.state = pygame.mouse.get_pressed()
Mouse.pos = pygame.mouse.get_pos()
@staticmethod
def getX():
return Mouse.pos[0]
@staticmethod
def getY():
return Mouse.pos[1]
@staticmethod
def left():
return Mouse.state[0] == 1
@staticmethod
def middle():
return Mouse.state[1] == 1
@staticmethod
def right():
return Mouse.state[2] == 1
@staticmethod
def pressed(ind):
return Mouse.oldstate[ind] == 0 and Mouse.state[ind] == 1
@staticmethod
def released(ind):
return Mouse.oldstate[ind] == 1 and Mouse.state[ind] == 0
@staticmethod
def leftPressed():
return Mouse.pressed(0)
@staticmethod
def leftReleased():
return Mouse.released(0)
@staticmethod
def middlePressed():
return Mouse.pressed(1)
@staticmethod
def middleReleased():
return Mouse.released(1)
@staticmethod
def rightPressed():
return Mouse.pressed(2)
@staticmethod
def rightReleased():
return Mouse.released(2)
class Keyboard:
oldkeys = [False for i in range(256)]
keys = oldkeys
@staticmethod
def init():
Keyboard.oldkeys = [False] * len(pygame.key.get_pressed())
Keyboard.keys = Keyboard.oldkeys
@staticmethod
def update():
Keyboard.oldkeys = Keyboard.keys
Keyboard.keys = pygame.key.get_pressed()
@staticmethod
def down(k, kmap=None):
if kmap is None:
kmap = Keyboard.keys
return kmap[k if type(k) is int else ord(k)]
@staticmethod
def up(k, kmap=None):
if kmap is None:
kmap = Keyboard.keys
return not Keyboard.down(k, kmap)
@staticmethod
def pressed(k):
return not Keyboard.down(k, Keyboard.oldkeys) and Keyboard.down(k)
@staticmethod
def released(k):
return not Keyboard.up(k, Keyboard.oldkeys) and Keyboard.up(k)