|
| 1 | +# Keyboard Configuration |
| 2 | + |
| 3 | +M60 is not just a USB HID device, but also a USB storage device. Python code can be saved and executed in the keyboard. When the keyboard powers on, it will run the Python file `code.py` in its USB storage. |
| 4 | +In `code.py`, we can modify its keymap, add a macro and add a new feature to keyboard. |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +The default content of `code.py` is: |
| 9 | + |
| 10 | +```python |
| 11 | + |
| 12 | +from PYKB import * |
| 13 | + |
| 14 | + |
| 15 | +keyboard = Keyboard() |
| 16 | + |
| 17 | +___ = TRANSPARENT |
| 18 | +BOOT = BOOTLOADER |
| 19 | +L1 = LAYER_TAP(1) |
| 20 | +L2D = LAYER_TAP(2, D) |
| 21 | +L3B = LAYER_TAP(3, B) |
| 22 | +LSFT4 = LAYER_MODS(4, MODS(LSHIFT)) |
| 23 | +RSFT4 = LAYER_MODS(4, MODS(RSHIFT)) |
| 24 | + |
| 25 | +# Semicolon & Ctrl |
| 26 | +SCC = MODS_TAP(MODS(RCTRL), ';') |
| 27 | + |
| 28 | +keyboard.keymap = ( |
| 29 | + # layer 0 |
| 30 | + ( |
| 31 | + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, |
| 32 | + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', |
| 33 | + CAPS, A, S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, |
| 34 | + LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', RSFT4, |
| 35 | + LCTRL, LGUI, LALT, SPACE, RALT, MENU, L1, RCTRL |
| 36 | + ), |
| 37 | + |
| 38 | + # layer 1 |
| 39 | + ( |
| 40 | + '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, |
| 41 | + ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, |
| 42 | + ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, |
| 43 | + ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, ___, ___, |
| 44 | + ___, ___, ___, ___, ___, ___, ___, ___ |
| 45 | + ), |
| 46 | + |
| 47 | + # layer 2 |
| 48 | + ( |
| 49 | + '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, |
| 50 | + ___, ___, ___, ___, ___, ___, ___,PGUP, ___, ___, ___,AUDIO_VOL_DOWN,AUDIO_VOL_UP,AUDIO_MUTE, |
| 51 | + ___, ___, ___, ___, ___, ___,LEFT,DOWN, UP,RIGHT, ___, ___, ___, |
| 52 | + ___, ___, ___, ___, ___, ___,PGDN, ___, ___, ___, ___, ___, |
| 53 | + ___, ___, ___, ___, ___, ___, ___, ___ |
| 54 | + ), |
| 55 | + |
| 56 | + # layer 3 |
| 57 | + ( |
| 58 | + BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, ___, ___, ___, |
| 59 | + ___, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,___,___,___, ___, |
| 60 | + ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, |
| 61 | + ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, |
| 62 | + ___, ___, ___, ___, ___, ___, ___, ___ |
| 63 | + ), |
| 64 | + |
| 65 | + # layer 4 |
| 66 | + ( |
| 67 | + '`', ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, |
| 68 | + ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, |
| 69 | + ___, ___, ___, D, ___, ___, ___, ___, ___, ___, ';', ___, ___, |
| 70 | + ___, ___, ___, ___, ___, B, ___, ___, ___, ___, ___, ___, |
| 71 | + ___, ___, ___, ___, ___, ___, ___, ___ |
| 72 | + ), |
| 73 | +) |
| 74 | + |
| 75 | + |
| 76 | +def macro_handler(dev, n, is_down): |
| 77 | + if is_down: |
| 78 | + dev.send_text('You pressed macro #{}\n'.format(n)) |
| 79 | + else: |
| 80 | + dev.send_text('You released macro #{}\n'.format(n)) |
| 81 | + |
| 82 | +def pairs_handler(dev, n): |
| 83 | + dev.send_text('You just triggered pair keys #{}\n'.format(n)) |
| 84 | + |
| 85 | + |
| 86 | +keyboard.macro_handler = macro_handler |
| 87 | +keyboard.pairs_handler = pairs_handler |
| 88 | + |
| 89 | +# Pairs: J & K, U & I |
| 90 | +keyboard.pairs = [{35, 36}, {20, 19}] |
| 91 | + |
| 92 | +keyboard.verbose = False |
| 93 | + |
| 94 | +keyboard.run() |
| 95 | + |
| 96 | +``` |
| 97 | + |
| 98 | +`keymap` contains multiple layers of keycodes. `macro_handler` is used to handle all macros. `pairs_handler` is used to handle any pair-keys. |
| 99 | + |
| 100 | +**When `code.py` is saved, the keyboard will reload it. If `code.py` has a syntax error, the keyboard will stop working. But, don't worry, it wouldn't damage the hardware. Fix the error and save it, then the keyboard will recover** |
| 101 | + |
| 102 | +If you know how Python works, configuring the keyboard would be very easy. If not, we have some examples to get started. |
| 103 | + |
| 104 | +1. To swap the positions of <kbd>Caps</kbd> and <kbd>LCtrl</kbd>, just swap `CAPS` and `LCTRL` in `layer 0` of `keymap`: |
| 105 | + |
| 106 | + ```python |
| 107 | + # layer 0 |
| 108 | + ( |
| 109 | + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, |
| 110 | + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', |
| 111 | + LCTRL, A, S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, |
| 112 | + LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', RSFT4, |
| 113 | + CAPS, LGUI, LALT, SPACE, RALT, MENU, L1, RCTRL |
| 114 | + ), |
| 115 | + ``` |
| 116 | + |
| 117 | +2. Instead of <kbd>D</kbd>, use <kbd>Caps</kbd> as a Tap-key to activate navigation functions. Only need to change `layer 0` to: |
| 118 | + |
| 119 | + ```python |
| 120 | + # layer 0 |
| 121 | + ( |
| 122 | + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, |
| 123 | + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', |
| 124 | + LAYER_TAP(2, CAPS), A, S, D, F, G, H, J, K, L, SCC, '"', ENTER, |
| 125 | + LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', RSFT4, |
| 126 | + LCTRL, LGUI, LALT, SPACE, RALT, MENU, L1, RCTRL |
| 127 | + ), |
| 128 | + ``` |
| 129 | + |
| 130 | +2. Add a new macro. Use <kbd>Fn</kbd> and <kbd>Enter</kbd> to trigger No.1 macro. Just add `MACRO(1)` to `layer 1`: |
| 131 | + |
| 132 | + ```python |
| 133 | + # layer 1 |
| 134 | + ( |
| 135 | + '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, |
| 136 | + ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, |
| 137 | + ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, MACRO(1), |
| 138 | + ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, ___, ___, |
| 139 | + ___, ___, ___, ___, ___, ___, ___, ___ |
| 140 | + ), |
| 141 | + ``` |
| 142 | + |
| 143 | + To define the function of the macro, please follow [the macro guide](macro.md) |
| 144 | + |
| 145 | +4. Use <kbd>RShift</kbd>, <kbd>RGUI</kbd>, <kbd>Fn</kbd> and <kbd>RCtrl</kbd> as Tap-keys. Tapping them outputs arrows keys (press & release quickly). Just change `layer 0` to: |
| 146 | + |
| 147 | + ```python |
| 148 | + # layer 0 |
| 149 | + ( |
| 150 | + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, |
| 151 | + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', |
| 152 | + CAPS, A, S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, |
| 153 | + LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', MODS_TAP(MODS(RSHIFT), UP), |
| 154 | + LCTRL, LGUI, LALT, SPACE, RALT, MODS_TAP(MODS(RGUI), LEFT), LAYER_TAP(1, DOWN), MODS_TAP(MODS(RCTRL), RIGHT) |
| 155 | + ), |
| 156 | + ``` |
0 commit comments