diff options
Diffstat (limited to 'joystick')
-rw-r--r-- | joystick/disable.wav | bin | 0 -> 419318 bytes | |||
-rw-r--r-- | joystick/enable.wav | bin | 0 -> 418996 bytes | |||
-rwxr-xr-x | joystick/joystick-input.py | 69 | ||||
-rwxr-xr-x | joystick/test-joystick.py | 22 |
4 files changed, 91 insertions, 0 deletions
diff --git a/joystick/disable.wav b/joystick/disable.wav Binary files differnew file mode 100644 index 0000000..ef2ddff --- /dev/null +++ b/joystick/disable.wav diff --git a/joystick/enable.wav b/joystick/enable.wav Binary files differnew file mode 100644 index 0000000..2e726b8 --- /dev/null +++ b/joystick/enable.wav 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 + diff --git a/joystick/test-joystick.py b/joystick/test-joystick.py new file mode 100755 index 0000000..a8ed6f1 --- /dev/null +++ b/joystick/test-joystick.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 + +import pygame + +pygame.display.init() +pygame.joystick.init() + +print ("Joystics: ", pygame.joystick.get_count()) +my_joystick = pygame.joystick.Joystick(0) +my_joystick.init() +clock = pygame.time.Clock() + +print (my_joystick.get_numbuttons()) +print (my_joystick.get_numhats()) +while 1: + for event in pygame.event.get(): + print (my_joystick.get_axis(0), my_joystick.get_axis(1)) + for i in range(my_joystick.get_numbuttons()): + print(i, my_joystick.get_button(i)) + clock.tick(40) + +pygame.quit () |