Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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

This comment has been minimized.

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

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