Skip to content

Instantly share code, notes, and snippets.

@V-FEXrt
Created May 4, 2023 01:13
Show Gist options
  • Select an option

  • Save V-FEXrt/6946ceb4868669fd9274ff3f5222aa13 to your computer and use it in GitHub Desktop.

Select an option

Save V-FEXrt/6946ceb4868669fd9274ff3f5222aa13 to your computer and use it in GitHub Desktop.
Basic Input Redirection Control
import socket
import struct
import time
import queue
addr = ("<an ip address>", 4950)
hid = 0x00000fff
touch = 0x02000000
circle = 0x007ff7ff
cpp = 0x80800081
interface = 0x00000000
def queue_hid(q, h):
to_send = struct.pack("I", h) + struct.pack("I", touch) + struct.pack("I", circle) + struct.pack("I", cpp) + struct.pack("I", interface)
q.put(to_send)
def empty_frame(q):
queue_hid(q, 0x00000FFF)
def sleep_for(q, ms):
q.put("SLEEP")
q.put(ms)
def hold_for(q, h, ms):
while ms > 0:
ms -= 50
queue_hid(q, h)
empty_frame(q)
empty_frame(q)
def fire_frame(q, h):
empty_frame(q)
empty_frame(q)
queue_hid(q, h)
queue_hid(q, h)
queue_hid(q, h)
empty_frame(q)
empty_frame(q)
def hold_up_for(q, ms):
hold_for(q, 0x00000FBF, ms)
def hold_down_for(q, ms):
hold_for(q, 0x00000F7F, ms)
def fire_left(q):
fire_frame(q, 0x00000FDF)
def fire_right(q):
fire_frame(q, 0x00000FEF)
def fire_up(q):
fire_frame(q, 0x00000FBF)
def fire_down(q):
fire_frame(q, 0x00000F7F)
def fire_a(q):
fire_frame(q, 0x00000FFE)
def fire_b(q):
fire_frame(q, 0x00000FFD)
def fire_x(q):
fire_frame(q, 0x00000BFF)
def fire_y(q):
fire_frame(q, 0x000007FF)
def fire_l(q):
fire_frame(q, 0x00000DFF)
def fire_l(q):
fire_frame(q, 0x00000EFF)
def fire_start(q):
fire_frame(q, 0x00000FF7)
def fire_select(q):
fire_frame(q, 0x00000FFB)
s = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
q = queue.Queue()
# Fills the queue with a stream of commands to execute
def fill_queue(q):
hold_up_for(q, 1 * 1000)
hold_down_for(q, 1 * 1000 - 50)
sleep_for(q, 0.5 * 1000)
# Loop forever, filling the queue with commands as needed
while True:
if q.empty():
fill_queue(q)
cmd = q.get()
if cmd == "SLEEP":
ms = q.get()
goal = ms
while ms > 0:
time.sleep(50 / 1000)
empty_frame(q)
ms -= 50
continue
time.sleep(50 / 1000)
s.sendto(cmd, addr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment