Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding mouse support, inspired by omg cable #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions duckyinpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import asyncio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.mouse import Mouse

# comment out these lines for non_US keyboards
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS as KeyboardLayout
Expand Down Expand Up @@ -75,6 +76,30 @@ def runScriptLine(line):
def sendString(line):
layout.write(line)

def parseMouse(line):
if(line[0:4] == "MOVE"):
coords = line[5:].split(" ")

if(len(coords) == 2):
x = int(coords[0])
y = int(coords[1])
mouse.move(x,y)
elif(len(coords) == 3):
# mouse wheel
x = int(coords[0])
y = int(coords[1])
wheel = int(coords[2])
mouse.move(x,y,wheel)
elif(line[0:5] == "CLICK"):
button = int(line[6:])
if(button == 1):
mouse.click(Mouse.LEFT_BUTTON)
elif(button == 2):
mouse.click(Mouse.MIDDLE_BUTTON)
elif(button == 3):
mouse.click(Mouse.MIDDLE_BUTTON)


def parseLine(line):
global defaultDelay
if(line[0:3] == "REM"):
Expand All @@ -97,11 +122,14 @@ def parseLine(line):
led.value = False
else:
led.value = True
elif(line[0:5] == "MOUSE"):
parseMouse(line[6:])
else:
newScriptLine = convertLine(line)
runScriptLine(newScriptLine)

kbd = Keyboard(usb_hid.devices)
mouse = Mouse(usb_hid.devices)
layout = KeyboardLayout(kbd)


Expand Down