-
Notifications
You must be signed in to change notification settings - Fork 0
/
joycon.py
109 lines (84 loc) · 2.15 KB
/
joycon.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
101
102
103
104
105
106
107
108
109
import pygame
from pygame.locals import *
# import time
import pyautogui
import sys
TaskSwitcher_statu = False
dragleft_statu = False
def left():
pyautogui.press('left')
def right():
pyautogui.press('right')
def up():
pyautogui.press('up')
def down():
pyautogui.press('down')
def enter():
pyautogui.press('enter')
def slideshow():
pyautogui.press('f5')
def Esc():
pyautogui.press('esc')
def TaskSwitcher():
global TaskSwitcher_statu
if TaskSwitcher_statu == False:
pyautogui.keyDown('alt')
pyautogui.press('tab')
else:
pyautogui.keyUp('alt')
TaskSwitcher_statu = not(TaskSwitcher_statu)
def dragleft():
global dragleft_statu
if dragleft_statu == False:
pyautogui.hotkey('ctrl', 'l')
else:
pyautogui.press('esc')
dragleft_statu = not(dragleft_statu)
switch={
'3': left,
'0': right,
'1': up,
'2': down,
'15': enter,
'9': slideshow,
'12': Esc,
'14': TaskSwitcher,
'11': dragleft
}
def main():
pygame.joystick.init()
joystick0 = pygame.joystick.Joystick(0)
joystick0.init()
print ("joystick start")
pygame.init()
pygame.event.set_allowed([QUIT,JOYBUTTONDOWN,JOYHATMOTION])
def threadfun():
y,x = 0,0
while True:
if x!=0 or y!=0:
pyautogui.move(x*(-40),y*(-40))
# time.sleep(5)
# postquit()
eventlist = pygame.event.get()
for e in eventlist:
if e.type == QUIT:
return
if e.type == JOYBUTTONDOWN:
input_button = str(e.button)
print('button :{}'.format(input_button))
switch[input_button]()
# if e.type == pygame.locals.JOYAXISMOTION:
# print('axis {} : {}'.format(e.axis,e.value))
if e.type == JOYHATMOTION:
position = e.value
print('hat : {}'.format(position))
y,x = position
def postquit():
pygame.event.post(pygame.event.Event(QUIT))
if __name__ == '__main__':
try:
main()
except pygame.error:
print ("joystick error")
sys.exit()
threadfun()