diff --git a/keytest.py b/keytest.py deleted file mode 100755 index 84d82ed..0000000 --- a/keytest.py +++ /dev/null @@ -1,97 +0,0 @@ -import time -import board -from digitalio import DigitalInOut, Direction, Pull -import usb_hid -from adafruit_hid.keyboard import Keyboard -from adafruit_hid.keycode import Keycode -from adafruit_hid.mouse import Mouse -from adafruit_hid.consumer_control import ConsumerControl - -led = DigitalInOut(board.LED) -led.direction = Direction.OUTPUT -led.value = True - -kbd = Keyboard(usb_hid.devices) -mse = Mouse(usb_hid.devices) -ctl = ConsumerControl(usb_hid.devices) - -pins = [ - board.GP0, # 0 1 2 - board.GP1, # 3 4 5 - board.GP2, # 6 7 8 - board.GP3, - board.GP4, - board.GP5, - board.GP6, - board.GP7, - board.GP8, -] - -testcode = 0x180 - -def press(key): - if key == 0: # xf86select - global testcode - ctl.send(testcode) - print("Keycode is % s" % testcode) - testcode += 1 - elif key == 1: # xf86print - ctl.send(0x208) - elif key == 2: - mse.press(Mouse.MIDDLE_BUTTON) - elif key == 3: - ctl.send(0x224) # back (browser) - elif key == 4: - ctl.send(0x225) # forward (browser) - elif key == 5: - mse.press(Mouse.RIGHT_BUTTON) - elif key == 6: # ctrl-w - kbd.press(Keycode.CONTROL) - kbd.press(Keycode.W) - kbd.release(Keycode.W) - kbd.release(Keycode.CONTROL) - elif key == 7: - # toggles scroll mode in ploopy nano using maddie layout - kbd.press(Keycode.KEYPAD_NUMLOCK) - kbd.release(Keycode.KEYPAD_NUMLOCK) - kbd.press(Keycode.KEYPAD_NUMLOCK) - kbd.release(Keycode.KEYPAD_NUMLOCK) - elif key == 8: - mse.press(Mouse.LEFT_BUTTON) - -def release(key): - if key == 2: - mse.release(Mouse.MIDDLE_BUTTON) - elif key == 5: - mse.release(Mouse.RIGHT_BUTTON) - elif key == 8: - mse.release(Mouse.LEFT_BUTTON) - -switches = [0, 1, 2, 3, 4, 5, 6, 7, 8] - -for i in range(9): - switches[i] = DigitalInOut(pins[i]) - switches[i].direction = Direction.INPUT - switches[i].pull = Pull.UP - -switch_state = [0, 0, 0, 0, 0, 0, 0, 0, 0] - -while True: - for button in range(9): - if switch_state[button] == 0: - if not switches[button].value: - try: - press(button) - except ValueError: # deals w six key limit - pass - switch_state[button] = 1 - - if switch_state[button] == 1: - if switches[button].value: - try: - release(button) - except ValueError: - pass - switch_state[button] = 0 - - time.sleep(0.01) # debounce