Linux Format

CREATING A SIMPLE RUBBER DUCKY

-

A rubber ducky is a device that imitates a keyboard. In this example, we’ll connect two switches to the Pico device and program one to imitate the Super-Key and the other to imitate the Print Screen key. First we add the USB Human Interface Device (HID) libraries to the Pico. Download the library files (https:// circuitpyt­hon.org/libraries), extract the archive and copy the adafruit_hid folder to the lib folder on the Pico.

First we import the libraries for digital IO and USB HID functional­ity. Second, we define a variable to represent the keyboard we will emulate. Next, the buttons and LED are initialise­d as three of the GPIO pins. Now we start an infinite while loop and read the state of the buttons. If the pin associated with button 1 goes high (showing the button has been pressed) we send the Super-Key scan code. Similarly, the pin linked to button 2 is scanned and when this goes high, the scan code for the print screen key is pressed. Test this by pressing the buttons and noting what happens. See the righthand side of the circuit diagram (left) to view the wiring diagram for this project. import usb_hid from adafruit_hid.keyboard import

Keyboard from adafruit_hid.keycode import

Keycode import time import digitalio import board

kbd = Keyboard(usb_hid.devices) button1 = digitalio.DigitalInO­ut(board.

GP20) button1.direction = digitalio.Direction.

INPUT button1.pull = digitalio.Pull.DOWN button2 = digitalio.DigitalInO­ut(board.

GP21) button2.direction = digitalio.Direction.

INPUT button2.pull = digitalio.Pull.DOWN led = digitalio.DigitalInO­ut(board.LED) led.direction = digitalio.Direction.

OUTPUT

def flashLed(): led.value = True time.sleep(0.1) led.value = False

while True: if button1.value == True: kbd.press(Keycode.WINDOWS) kbd.release_all() print('Button1') flashLed() if button2.value == True: kbd.press(Keycode.PRINT_SCREEN) kbd.release_all() print('Button2') flashLed() time.sleep(0.20)

Newspapers in English

Newspapers from Australia