Skip to content

Instantly share code, notes, and snippets.

@SuperSonicHub1
Created April 22, 2024 03:55
Show Gist options
  • Save SuperSonicHub1/e076895be3712288dea78d2ad445f044 to your computer and use it in GitHub Desktop.
Save SuperSonicHub1/e076895be3712288dea78d2ad445f044 to your computer and use it in GitHub Desktop.
CircuitPython implementation of a "Vim clutch" for the RPi Pico
import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
kbd = Keyboard(usb_hid.devices)
button = digitalio.DigitalInOut(board.GP13)
button.switch_to_input(pull=digitalio.Pull.UP)
def vim_clutch(state: bool):
"""
On press, send `i` key.
On release, send `Esc` key.
https://github.com/alevchuk/vim-clutch
"""
if state:
kbd.send(Keycode.I)
else:
kbd.send(Keycode.ESCAPE)
def big_key(*keycodes):
return lambda state: kbd.press(*keycodes) if state else kbd.release(*keycodes)
prev = None
while True:
state = not button.value
if state != prev:
# big_key(Keycode.GUI)(state)
big_key(Keycode.CONTROL)(state)
# big_key(Keycode.B)(state)
# vim_clutch(state)
prev = state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment