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

Support for keyboard layout switching and more payload scripts #241

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Copy the adafruit-circuitpython-raspberry_pi_pico_w-en_US-8.0.0.uf2 file to the

6. Follow the instructions in README.md to enter setup mode

7. Copy your payload as payload.dd to the root of the CIRCUITPY
7. Copy your payload as payload[0-15].dd to the payloads directory

8. Unplug the device from the USB port and remove the setup jumper.

Expand Down Expand Up @@ -149,16 +149,19 @@ Pico W: The default mode is USB mass storage **disabled**
## Multiple payloads

Multiple payloads can be stored on the Pico and Pico W.
To select a payload, ground one of these pins:
- GP4 - payload.dd
- GP5 - payload2.dd
- GP10 - payload3.dd
- GP11 - payload4.dd
To select a payload from the 'payloads' directory, ground combination of these pins:
- GP2 - value 1
- GP3 - value 2
- GP4 - value 4
- GP5 - value 8

default value is 0, grounding multiple pins at the same time sums their values. You can access maximum of 16 payloads this way payload0.dd - payload15.dd

## Changing Keyboard Layouts

Copied from [Neradoc/Circuitpython_Keyboard_Layouts](https://github.com/Neradoc/Circuitpython_Keyboard_Layouts/blob/main/PICODUCKY.md)

This fork allows you to switch between layout by grounding one of these pins: GP18, GP19, GP20, GP21, or none for default layout.
#### How to use one of these layouts with the pico-ducky repository.

**Go to the [latest release page](https://github.com/Neradoc/Circuitpython_Keyboard_Layouts/releases/latest), look if your language is in the list.**
Expand Down
1 change: 1 addition & 0 deletions code.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ async def main_loop():
await asyncio.gather(pico_led_task, button_task)

asyncio.run(main_loop())

73 changes: 32 additions & 41 deletions duckyinpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,28 @@
import usb_hid
from adafruit_hid.keyboard import Keyboard

# comment out these lines for non_US keyboards
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS as KeyboardLayout

langSwitchPin1 = digitalio.DigitalInOut(board.GP18)
langSwitchPin1.switch_to_input(pull=digitalio.Pull.UP)
langSwitchPin2 = digitalio.DigitalInOut(board.GP19)
langSwitchPin2.switch_to_input(pull=digitalio.Pull.UP)
langSwitchPin3 = digitalio.DigitalInOut(board.GP20)
langSwitchPin3.switch_to_input(pull=digitalio.Pull.UP)
langSwitchPin4 = digitalio.DigitalInOut(board.GP21)
langSwitchPin4.switch_to_input(pull=digitalio.Pull.UP)

# define your layouts here
if not langSwitchPin1.value:
from adafruit_hid.keyboard_layout_win_cz import KeyboardLayout # qwertz
elif not langSwitchPin2.value:
from adafruit_hid.keyboard_layout_win_cz1 import KeyboardLayout # qwerty
elif not langSwitchPin3.value:
from adafruit_hid.keyboard_layout_win_uk import KeyboardLayout
elif not langSwitchPin4.value:
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS as KeyboardLayout
else:
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS as KeyboardLayout

from adafruit_hid.keycode import Keycode

# uncomment these lines for non_US keyboards
Expand Down Expand Up @@ -125,15 +145,6 @@ def parseLine(line):
button1_pin.pull = Pull.UP # turn on internal pull-up resistor
button1 = Debouncer(button1_pin)

#init payload selection switch
payload1Pin = digitalio.DigitalInOut(GP4)
payload1Pin.switch_to_input(pull=digitalio.Pull.UP)
payload2Pin = digitalio.DigitalInOut(GP5)
payload2Pin.switch_to_input(pull=digitalio.Pull.UP)
payload3Pin = digitalio.DigitalInOut(GP10)
payload3Pin.switch_to_input(pull=digitalio.Pull.UP)
payload4Pin = digitalio.DigitalInOut(GP11)
payload4Pin.switch_to_input(pull=digitalio.Pull.UP)

def getProgrammingStatus():
# check GP0 for setup mode
Expand Down Expand Up @@ -168,36 +179,16 @@ def runScript(file):
print("Unable to open file ", file)

def selectPayload():
global payload1Pin, payload2Pin, payload3Pin, payload4Pin
payload = "payload.dd"
# check switch status
# payload1 = GPIO4 to GND
# payload2 = GPIO5 to GND
# payload3 = GPIO10 to GND
# payload4 = GPIO11 to GND
payload1State = not payload1Pin.value
payload2State = not payload2Pin.value
payload3State = not payload3Pin.value
payload4State = not payload4Pin.value

if(payload1State == True):
payload = "payload.dd"

elif(payload2State == True):
payload = "payload2.dd"

elif(payload3State == True):
payload = "payload3.dd"

elif(payload4State == True):
payload = "payload4.dd"

else:
# if all pins are high, then no switch is present
# default to payload1
payload = "payload.dd"

return payload
fileNameFormat = "payloads/payload%d.dd"
fileNumber = 0
limit = 15
readPins = [board.GP5, board.GP4, board.GP3, board.GP2]
for pin in readPins:
pinValue = digitalio.DigitalInOut(pin)
pinValue.switch_to_input(pull=digitalio.Pull.UP)
fileNumber <<= 1
fileNumber += pinValue.value
return fileNameFormat % (limit - fileNumber)

async def blink_led(led):
print("Blink")
Expand Down
12 changes: 6 additions & 6 deletions payload.dd → payloads/payload0.dd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
REM The next four lines open Notepad in Windows and type "Hello World!"
GUI r
STRING notepad
ENTER
DELAY 250
STRING Hello World!
REM The next four lines open Notepad in Windows and type "Hello World!"
GUI r
STRING notepad
ENTER
DELAY 250
STRING Hello World!