-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinput_read_gamepad.py
More file actions
39 lines (28 loc) · 983 Bytes
/
input_read_gamepad.py
File metadata and controls
39 lines (28 loc) · 983 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
# Reading advanced gamepad state
import harfang as hg
hg.InputInit()
hg.WindowSystemInit()
win = hg.NewWindow('Harfang - Read Gamepad', 320, 200)
gamepad = hg.Gamepad()
while not hg.ReadKeyboard().Key(hg.K_Escape) and hg.IsWindowOpen(win):
gamepad.Update()
if gamepad.Connected():
print('Gamepad slot 0 was just connected')
if gamepad.Disconnected():
print('Gamepad slot 0 was just disconnected')
if gamepad.Pressed(hg.GB_ButtonA):
print('Gamepad button A pressed')
if gamepad.Pressed(hg.GB_ButtonB):
print('Gamepad button B pressed')
if gamepad.Pressed(hg.GB_ButtonX):
print('Gamepad button X pressed')
if gamepad.Pressed(hg.GB_ButtonY):
print('Gamepad button Y pressed')
axis_left_x = gamepad.Axes(hg.GA_LeftX)
if abs(axis_left_x) > 0.1:
print('Gamepad axis left X: %r' % axis_left_x)
axis_left_y = gamepad.Axes(hg.GA_LeftY)
if abs(axis_left_y) > 0.1:
print('Gamepad axis left Y: %r' % axis_left_y)
hg.UpdateWindow(win)
hg.DestroyWindow(win)