Skip to content

Instantly share code, notes, and snippets.

@omiq
Created July 20, 2018 02:21
Show Gist options
  • Save omiq/48f305cfb9ef7c76748c7f9db4293145 to your computer and use it in GitHub Desktop.
Save omiq/48f305cfb9ef7c76748c7f9db4293145 to your computer and use it in GitHub Desktop.
Raspberry Pi USB keyboard emulator
import time
import RPi.GPIO as GPIO
# We are going to use the BCM numbering
GPIO.setmode(GPIO.BCM)
# Set pin 26 as input using pull up resistor
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# function to send the data
def write_report(report):
with open('/dev/hidg0', 'rb+') as fd:
fd.write(report.encode())
# infinite loop to check the pins and send data
while True:
if not(GPIO.input(26)):
# shift-cmd-5
shift_cmd_5 = str(0b01010000) + "\0\x22\0\0\0\0\0"
write_report(shift_cmd_5)
print("SNAP!!")
time.sleep(0.2)
write_report("\0\0\0\0\0\0\0\0")
@haimiko
Copy link

haimiko commented Aug 8, 2018

Anyone know what the scancode sequence is for ctrl+alt+del?
I tried modifier 0b10100000 (160\x0\x4c\x0\x0\x0\x0\x0) but that didn't work.

@haimiko
Copy link

haimiko commented Aug 9, 2018

NM figured it out. The LSB is on the right so the modifier would be 5
ctrl+alt+del == "5\x0\x4c\x0\x0\x0\x0\x0"

echo -ne "5\x0\x4c\x0\x0\x0\x0\x0" > /dev/hidg0 ;echo -ne "\x0\x0\x0\x0\x0\x0\x0\x0" > /dev/hidg0

@yeskhentem
Copy link

How would you do Windows+R (Run)? I can't seem to figure it out.

str(0b00010000) + "\0\x15\0\0\0\0" does not seem to work.

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