Skip to content

Instantly share code, notes, and snippets.

@lewangdev
Created May 12, 2023 06:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewangdev/2a02fa2e48de3bdea3ce8094ce89e7af to your computer and use it in GitHub Desktop.
Save lewangdev/2a02fa2e48de3bdea3ce8094ce89e7af to your computer and use it in GitHub Desktop.
read xbox 360 joystick event
def joystickLoop(eventFile):
FORMAT = 'llHHI'
EVENT_SIZE = struct.calcsize(FORMAT)
with open(eventFile, 'rb') as infile:
while True:
event = infile.read(EVENT_SIZE)
_, _, t, c, v = struct.unpack(FORMAT, event)
print(t, c, v)
if t == 3 and v == 4294967295:
if c == 17:
# press UP:
elif c == 16:
# press LEFT
elif t == 3 and v == 1:
if c == 17:
# press DOWN:
elif c == 16:
# press RIGHT
elif t == 3 and v == 0:
if c == 17 or c == 16:
# pass
elif t == 1 and v == 1:
if c == 307:
# Camera up
if c == 305:
# Cameta down
if c == 304:
# Cameta right
if c == 308:
# Camera left
elif t == 1 and v == 1:
pass
@song940
Copy link

song940 commented May 12, 2023

之前也做了类似的东西:
https://github.com/song940/input-event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment