|
| 1 | +import time |
| 2 | +import board |
| 3 | +import busio |
| 4 | +from adafruit_neokey.neokey1x4 import NeoKey1x4 |
| 5 | +import usb_hid |
| 6 | +from adafruit_hid.keyboard import Keyboard |
| 7 | +from adafruit_hid.keycode import Keycode |
| 8 | + |
| 9 | +# use STEMMA I2C bus on RP2040 QT Py |
| 10 | +i2c_bus = busio.I2C(board.SCL1, board.SDA1) |
| 11 | + |
| 12 | +# Create a NeoKey object |
| 13 | +neokey = NeoKey1x4(i2c_bus, addr=0x30) |
| 14 | + |
| 15 | +# create a keyboard object |
| 16 | +keyboard = Keyboard(usb_hid.devices) |
| 17 | + |
| 18 | +print("NeoKey Emoji keyboard - macOS") |
| 19 | + |
| 20 | +# states for key presses |
| 21 | +key_0_state = False |
| 22 | +key_1_state = False |
| 23 | +key_2_state = False |
| 24 | +key_3_state = False |
| 25 | + |
| 26 | +# update these arrays to customize your emojis |
| 27 | +# cat face emoji |
| 28 | +emoji_0 = [Keycode.C, Keycode.A, Keycode.T, Keycode.DOWN_ARROW, Keycode.ENTER] |
| 29 | +# lightning bolt emoji |
| 30 | +emoji_1 = [Keycode.V, Keycode.O, Keycode.L, Keycode.T, Keycode.DOWN_ARROW, Keycode.ENTER] |
| 31 | +# control panel emoji |
| 32 | +emoji_2 = [Keycode.C, Keycode.O, Keycode.N, Keycode.T, Keycode.R, Keycode.O, |
| 33 | + Keycode.DOWN_ARROW, Keycode.ENTER] |
| 34 | +# guitar emoji |
| 35 | +emoji_3 = [Keycode.G, Keycode.U, Keycode.I, Keycode.T, Keycode.DOWN_ARROW, Keycode.ENTER] |
| 36 | + |
| 37 | +while True: |
| 38 | + # switch debouncing |
| 39 | + # also turns off NeoPixel on release |
| 40 | + if not neokey[0] and key_0_state: |
| 41 | + key_0_state = False |
| 42 | + neokey.pixels[0] = 0x0 |
| 43 | + if not neokey[1] and key_1_state: |
| 44 | + key_1_state = False |
| 45 | + neokey.pixels[1] = 0x0 |
| 46 | + if not neokey[2] and key_2_state: |
| 47 | + key_2_state = False |
| 48 | + neokey.pixels[2] = 0x0 |
| 49 | + if not neokey[3] and key_3_state: |
| 50 | + key_3_state = False |
| 51 | + neokey.pixels[3] = 0x0 |
| 52 | + |
| 53 | + # if 1st neokey is pressed... |
| 54 | + if neokey[0] and not key_0_state: |
| 55 | + print("Button A") |
| 56 | + # turn on NeoPixel |
| 57 | + neokey.pixels[0] = 0xFF0000 |
| 58 | + # open macOS emoji menu |
| 59 | + keyboard.send(Keycode.CONTROL, Keycode.COMMAND, Keycode.SPACE) |
| 60 | + # delay for opening menu |
| 61 | + time.sleep(.2) |
| 62 | + # send key presses for emoji_0 |
| 63 | + for i in emoji_0: |
| 64 | + keyboard.send(i) |
| 65 | + time.sleep(0.05) |
| 66 | + # update key state |
| 67 | + key_0_state = True |
| 68 | + |
| 69 | + # if 2nd neokey is pressed... |
| 70 | + if neokey[1] and not key_1_state: |
| 71 | + print("Button B") |
| 72 | + # turn on NeoPixel |
| 73 | + neokey.pixels[1] = 0xFFFF00 |
| 74 | + # open macOS emoji menu |
| 75 | + keyboard.send(Keycode.CONTROL, Keycode.COMMAND, Keycode.SPACE) |
| 76 | + # delay for opening menu |
| 77 | + time.sleep(.2) |
| 78 | + # send key presses for emoji_1 |
| 79 | + for i in emoji_1: |
| 80 | + keyboard.send(i) |
| 81 | + time.sleep(0.05) |
| 82 | + # update key state |
| 83 | + key_1_state = True |
| 84 | + |
| 85 | + # if 3rd neokey is pressed... |
| 86 | + if neokey[2] and not key_2_state: |
| 87 | + print("Button C") |
| 88 | + # turn on NeoPixel |
| 89 | + neokey.pixels[2] = 0x00FF00 |
| 90 | + # open macOS emoji menu |
| 91 | + keyboard.send(Keycode.CONTROL, Keycode.COMMAND, Keycode.SPACE) |
| 92 | + # delay for opening menu |
| 93 | + time.sleep(.2) |
| 94 | + # send key presses for emoji_2 |
| 95 | + for i in emoji_2: |
| 96 | + keyboard.send(i) |
| 97 | + time.sleep(0.05) |
| 98 | + # update key state |
| 99 | + key_2_state = True |
| 100 | + |
| 101 | + # if 4th neokey is pressed... |
| 102 | + if neokey[3] and not key_3_state: |
| 103 | + print("Button D") |
| 104 | + # turn on NeoPixel |
| 105 | + neokey.pixels[3] = 0x00FFFF |
| 106 | + # open macOS emoji menu |
| 107 | + keyboard.send(Keycode.CONTROL, Keycode.COMMAND, Keycode.SPACE) |
| 108 | + # delay for opening menu |
| 109 | + time.sleep(.2) |
| 110 | + # send key presses for emoji_3 |
| 111 | + for i in emoji_3: |
| 112 | + keyboard.send(i) |
| 113 | + time.sleep(0.05) |
| 114 | + # update key state |
| 115 | + key_3_state = True |
0 commit comments