diff options
author | Robert Scheibe <robert.scheibe@mailbox.org> | 2020-06-18 11:37:11 +0200 |
---|---|---|
committer | Robert Scheibe <robert.scheibe@mailbox.org> | 2020-06-18 11:37:11 +0200 |
commit | d3a4e5b0e664aea57c4cce59631785ff5b61eabf (patch) | |
tree | ebfb8bddea356b72410ba9c2ead488deae2dfdf1 /joystick/joystick-input.py |
initial commit
Diffstat (limited to 'joystick/joystick-input.py')
-rwxr-xr-x | joystick/joystick-input.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/joystick/joystick-input.py b/joystick/joystick-input.py new file mode 100755 index 0000000..fb49765 --- /dev/null +++ b/joystick/joystick-input.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3 + +import inputs,os,pygame + +print(inputs.devices.gamepads) + +pads = inputs.devices.gamepads +select=0 +start=0 +disable_pad=False + +pygame.init() +enable=pygame.mixer.Sound('enable.wav') +disable=pygame.mixer.Sound('disable.wav') + +while True: + events = inputs.get_gamepad() + for event in events: + #print(event.ev_type, event.code, event.state) + if event.code == 'ABS_Y' and event.state == 255: + #print("down") + if not disable_pad: + os.system("xte 'key Down'") + elif event.code == 'ABS_Y' and event.state == 0: + #print("up") + if not disable_pad: + os.system("xte 'key Up'") + elif event.code == 'ABS_X' and event.state == 255: + #print("right") + if not disable_pad: + os.system("xte 'key Right'") + elif event.code == 'ABS_X' and event.state == 0: + #print("left") + if not disable_pad: + os.system("xte 'key Left'") + elif event.code == 'BTN_TRIGGER' and event.state == 1: + #print("B") + if not disable_pad: + os.system("xte 'key Escape'") + start=1 + elif event.code == 'BTN_TRIGGER' and event.state == 0: + #print("B") + start=0 + elif event.code == 'BTN_THUMB' and event.state == 1: + #print("A") + if not disable_pad: + os.system("xte 'key Return'") + select=1 + elif event.code == 'BTN_THUMB' and event.state == 0: + #print("select") + select=0 + elif event.code == 'BTN_BASE3' and event.state == 1: + #print("select") + if not disable_pad: + os.system("xte 'keydown Meta_L' 'key F4' 'keyup Meta_L'") + elif event.code == 'BTN_BASE4' and event.state == 1: + #print("start") + if not disable_pad: + os.system("xte 'key Super_L'") + if start == 1 and select == 1: + print("toggle disable pad") + disable_pad=not disable_pad + if disable_pad: + disable.play() + else: + enable.play() + select=0 + start=0 + |