Close

main.py

A project log for e accent aigu, é, - big red button

Sometimes you just need a button for a letter with an accent

sciencedude1990sciencedude1990 06/25/2023 at 17:370 Comments
# Imports
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import digitalio
import time
import board

# Make a keyboard
kbd = Keyboard(usb_hid.devices)

# The big red button
btn_red = digitalio.DigitalInOut(board.GP0)
btn_red.direction = digitalio.Direction.INPUT
btn_red.pull = digitalio.Pull.UP

# State variable
keydown = 1

# Loop forever
while True:
    
    if btn_red.value == 1:
        print("1")
        # Set the state variable back to 1
        keydown = 1        
    else:        
        print("0")
        
        # Only if the state variable is 1, press the keys (stops rapidly keying)
        if keydown == 1:
            
            # Press and hold the LEFT ALT
            kbd.press(Keycode.LEFT_ALT)
            
            # Press and release keypad 0
            kbd.press(Keycode.KEYPAD_ZERO)
            kbd.release(Keycode.KEYPAD_ZERO)
            
            # Press and release keypad 2
            kbd.press(Keycode.KEYPAD_TWO)
            kbd.release(Keycode.KEYPAD_TWO)
            
            # Press and release keypad 3
            kbd.press(Keycode.KEYPAD_THREE)
            kbd.release(Keycode.KEYPAD_THREE)
            
            # Press and release keypad 3
            kbd.press(Keycode.KEYPAD_THREE)
            kbd.release(Keycode.KEYPAD_THREE)
            
            # Release all keys
            kbd.release_all()
    
        # Set the state variable
        keydown = 0
        
    # Sleep for a bit
    time.sleep(0.03)
    

Discussions