Created
April 10, 2020 16:39
-
-
Save GluTbl/9f899f7b1233c912a28aa959e6ace014 to your computer and use it in GitHub Desktop.
HID gamepade move detect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from time import sleep | |
from pynput.mouse import Listener,Button, Controller | |
mouse = Controller() | |
def on_move(x, y): | |
global p1 | |
p1=mouse.position | |
return False | |
def on_click(x, y, button, pressed): | |
return False | |
def on_scroll(x, y, dx, dy): | |
pass | |
###################################### | |
####define your variable here | |
p1=mouse.position | |
middle=(635,486) | |
minimumtime=80 | |
################################# | |
milli=int(round(time.time() * 1000)) | |
while True: | |
with Listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll) as listener: | |
listener.join() | |
sleep(0.01) | |
p2 = mouse.position | |
mouse.position=middle | |
deltax=p1[0]-p2[0] | |
deltay=p1[1]-p2[1] | |
# print("deltax: " ,deltax) | |
# print("deltay: " ,deltay) | |
if(abs(deltax)>abs(deltay)): | |
xmove=True | |
else: | |
xmove=False | |
curr=int(round(time.time() * 1000)) | |
dif=curr-milli | |
milli=curr | |
if dif < minimumtime: | |
# print("Too early to trigger") | |
pass | |
else: | |
if xmove: | |
if deltax > 0: | |
print("Left") | |
else: | |
print("Right") | |
else: | |
if deltay > 0: | |
print("Up") | |
else: | |
print("Down") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment