import time
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import json
# Define the button pins
next_button_pin = board.GP5
type_button_pin = board.GP6
# Initialize the buttons
next_button = digitalio.DigitalInOut(next_button_pin)
next_button.direction = digitalio.Direction.INPUT
next_button.pull = digitalio.Pull.DOWN
type_button = digitalio.DigitalInOut(type_button_pin)
type_button.direction = digitalio.Direction.INPUT
type_button.pull = digitalio.Pull.DOWN
# Define the HID keyboard
keyboard = Keyboard(usb_hid.devices)
# Load passwords from JSON file
with open("passwords.json", "r") as json_file:
password_data = json.load(json_file)
# Extract the passwords from the JSON data
passwords = []
for entry in password_data.values():
if "username" in entry and "password" in entry:
passwords.append(entry)
# Index to keep track of the current password
current_password_index = 0
# Function to emulate typing the password
def type_password(username, password):
keyboard_layout = KeyboardLayoutUS(keyboard) # Change this if you are using a different keyboard layout
keyboard_layout.write(username)
keyboard_layout.press(Keycode.TAB)
keyboard_layout.release(Keycode.TAB)
time.sleep(0.1)
keyboard_layout.write(password)
keyboard_layout.press(Keycode.ENTER)
keyboard_layout.release_all()
# Main loop
while True:
if next_button.value:
current_password_index = (current_password_index + 1) % len(passwords)
time.sleep(0.5) # Debounce delay
if type_button.value:
password_entry = passwords[current_password_index]
username = password_entry["username"]
password = password_entry["password"]
type_password(username, password)
time.sleep(1) # Wait for 1 second between passwords