From e0f4eba1d12cc11820f560dc451791ad59cde915 Mon Sep 17 00:00:00 2001 From: galenzhao Date: Tue, 12 Jan 2021 20:02:40 +0800 Subject: [PATCH 01/10] add ls, du, ip add customer name add flow led --- code.py | 21 +++++++++++++++------ keyboard/__init__.py | 2 +- keyboard/model/m60.py | 12 +++++++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/code.py b/code.py index d792863..edc84f8 100644 --- a/code.py +++ b/code.py @@ -22,9 +22,9 @@ ( ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', RSFT4, - LCTRL, LGUI, LALT, SPACE, RALT, MENU, L1, RCTRL + LCTRL, LGUI, LALT, SPACE, RALT, MENU, RCTRL, L1 ), # layer 1 @@ -32,8 +32,8 @@ '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, ___, ___ + ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, UP, ___, + ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ ), # layer 2 @@ -106,7 +106,13 @@ def macro_handler(dev, n, is_down): dev.send_text('You released macro #{}\n'.format(n)) def pairs_handler(dev, n): - dev.send_text('You just triggered pair keys #{}\n'.format(n)) + #dev.send_text('You just triggered pair keys #{}\n'.format(n)) + if n == 0: + dev.send_text('ls -alh --color\n') + elif n == 1: + dev.send_text('du -sh *\n') + elif n == 2: + dev.send_text('ifconfig; ip addr') keyboard.macro_handler = macro_handler @@ -119,7 +125,10 @@ def pairs_handler(dev, n): # LCTRL(53) LGUI(54) LALT(55) SPACE(56) RALT(57) MENU(58) Fn(59) RCTRL(60) # Pairs: J & K, U & I -keyboard.pairs = [{35, 36}, {20, 19}] +# 1. ls +# 2. du +# 3. ip +keyboard.pairs = [{37, 30}, {31, 20}, {19, 17}, {35, 36}, {20, 19}] # keyboard.verbose = False diff --git a/keyboard/__init__.py b/keyboard/__init__.py index 847124f..4aea99c 100644 --- a/keyboard/__init__.py +++ b/keyboard/__init__.py @@ -267,7 +267,7 @@ def set_bt_id(self, n): address = _bleio.Address(uid, _bleio.Address.RANDOM_STATIC) try: self.ble._adapter.address = address - name = "PYKB {}".format(n) + name = "galen's PYKB {}".format(n) self.advertisement.complete_name = name self.ble.name = name self.ble_id = n diff --git a/keyboard/model/m60.py b/keyboard/model/m60.py index 7ebcb83..9af3e16 100644 --- a/keyboard/model/m60.py +++ b/keyboard/model/m60.py @@ -166,7 +166,8 @@ def __init__(self): self.blackhole, self.pinwheel, self.beacon, - self.beacon2 + self.beacon2, + self.flow ) self.set_mode(6) self.enabled = False @@ -223,6 +224,15 @@ def toggle(self): else: self.off() + def flow(self): + i = self.n + self.pixel(i, 0xff, 0xff, 0xff) + self.pixel(i-1 if i-1>=0 else 63, 0, 0, 0) + + self.update() + self.n = (i + 1) & 63 + return True + def mono(self): self.on(*hsv_to_rgb(*self.hsv)) From b0be3b70597a1aeeac53613d76706b1dee74d2e9 Mon Sep 17 00:00:00 2001 From: galenzhao Date: Thu, 14 Jan 2021 15:43:24 +0800 Subject: [PATCH 02/10] add light -= --- code.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/code.py b/code.py index edc84f8..e97b5dd 100644 --- a/code.py +++ b/code.py @@ -47,10 +47,10 @@ # layer 3 ( - BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, ___, ___, ___, + BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, VAL_RGB, RGB_VAL, ___, RGB_MOD, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,___,___,___, ___, RGB_TOGGLE,HUE_RGB,RGB_HUE,SAT_RGB,RGB_SAT,___,___,___,___,___,___,___, ___, - ___, ___, ___, ___, ___, ___, ___, ___,VAL_RGB,RGB_VAL, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___,___,___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___ ), @@ -100,10 +100,18 @@ } def macro_handler(dev, n, is_down): - if is_down: - dev.send_text('You pressed macro #{}\n'.format(n)) - else: - dev.send_text('You released macro #{}\n'.format(n)) + if n == 2: + if is_down: + dev.backlight.set_brightness(0) + + elif n == 3: + if is_down: + dev.backlight.set_brightness(255) + + #if is_down: + # dev.send_text('You pressed macro #{}\n'.format(n)) + #else: + # dev.send_text('You released macro #{}\n'.format(n)) def pairs_handler(dev, n): #dev.send_text('You just triggered pair keys #{}\n'.format(n)) From 177624acb70ddae00036809739c1451a3d564138 Mon Sep 17 00:00:00 2001 From: galenzhao Date: Thu, 14 Jan 2021 15:43:49 +0800 Subject: [PATCH 03/10] slow flow led --- keyboard/model/m60.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/keyboard/model/m60.py b/keyboard/model/m60.py index 9af3e16..11ba950 100644 --- a/keyboard/model/m60.py +++ b/keyboard/model/m60.py @@ -223,14 +223,35 @@ def toggle(self): self.set_mode(self.mode) else: self.off() +# ESC(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9) 0(10) -(11) =(12) BACKSPACE(13) +# TAB(27) Q(26) W(25) E(24) R(23) T(22) Y(21) U(20) I(19) O(18) P(17) [(16) ](15) \(14) +# CAPS(28) A(29) S(30) D(31) F(32) G(33) H(34) J(35) K(36) L(37) ;(38) "(39) ENTER(40) +#LSHIFT(52) Z(51) X(50) C(49) V(48) B(47) N(46) M(45) ,(44) .(43) /(42) RSHIFT(41) +# LCTRL(53) LGUI(54) LALT(55) SPACE(56) RALT(57) MENU(58) Fn(59) RCTRL(60) +#No.61 and No.62 are under the space key. No.63 is at the back of keyboard. + def flow(self): + stepby = 10 + #print(self.n) i = self.n - self.pixel(i, 0xff, 0xff, 0xff) - self.pixel(i-1 if i-1>=0 else 63, 0, 0, 0) + j = int(i/stepby) + self.pixel(j, 0xff, 0xff, 0xff) + self.pixel(j-1 if j-1>=0 else 60, 0, 0, 0) + if j == 56: + self.pixel(61, 0xff, 0xff, 0xff) + self.pixel(62, 0xff, 0xff, 0xff) + else: + self.pixel(61, 0, 0, 0) + self.pixel(62, 0, 0, 0) + self.update() - self.n = (i + 1) & 63 + #self.n = (i + 1) & (60*stepby+stepby-1) + self.n = i + 1 + if self.n > (60*stepby+stepby-1): + self.n = 0 + return True def mono(self): From 869ae1ba1255193210a60092c8193e09f09bbe3d Mon Sep 17 00:00:00 2001 From: galenzhao Date: Sat, 16 Jan 2021 12:44:25 +0800 Subject: [PATCH 04/10] add fill default keymap to profiles --- code.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/code.py b/code.py index e97b5dd..56aeaf0 100644 --- a/code.py +++ b/code.py @@ -78,7 +78,17 @@ # Connection not in this map will use default keymap defined above. keyboard.profiles = { # For example, BT8 is connected to a Mac - "BT8": ( + "USB": ( + # layer 0 + ( + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', + CAPS, A, S, D, F, G, H, J, K, L, SCC, '"', ENTER, + LSHIFT,Z, X, C, V, B, N, M, ',', '.', '/', RSHIFT, + LCTRL, LALT, LGUI, SPACE, MENU, RALT, L1, RCTRL + ), + ), + "BT1": ( # layer 0 ( ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, @@ -93,12 +103,30 @@ '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___,BOOT, ___,MACRO(1), ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, ___, ___ + ___, ___, ___, ___, ___,BOOT, ___,MACRO(1), ___, ___, UP, ___, + ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ ), ) } +# add default keymap to profiles +default_keymap_count = len(keyboard.keymap) +for i in keyboard.profiles.keys(): + profile_key_maps = keyboard.profiles.get(i) + profile_layer_count = len(profile_key_maps) + + # insert default + keymap_profile = list(profile_key_maps) + for x in range(profile_layer_count, default_keymap_count): + default_keymap = keyboard.keymap[x] + keymap_profile.append(default_keymap) + + keyboard.profiles[i] = tuple(keymap_profile) + + +#print(keyboard.profiles) + + def macro_handler(dev, n, is_down): if n == 2: if is_down: From 81ed97424e4bae137c3ea05e5d4283824a9524ed Mon Sep 17 00:00:00 2001 From: galenzhao Date: Sat, 16 Jan 2021 18:35:01 +0800 Subject: [PATCH 05/10] change fn& add l5s --- code.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code.py b/code.py index 56aeaf0..ec18543 100644 --- a/code.py +++ b/code.py @@ -83,9 +83,9 @@ ( ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, S, D, F, G, H, J, K, L, SCC, '"', ENTER, - LSHIFT,Z, X, C, V, B, N, M, ',', '.', '/', RSHIFT, - LCTRL, LALT, LGUI, SPACE, MENU, RALT, L1, RCTRL + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, + LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 ), ), "BT1": ( @@ -93,9 +93,9 @@ ( ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, S, D, F, G, H, J, K, L, SCC, '"', ENTER, - LSHIFT,Z, X, C, V, B, N, M, ',', '.', '/', RSHIFT, - LCTRL, LALT, LGUI, SPACE, MENU, RALT, L1, RCTRL + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, + LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 ), # layer 1 From 3667af687f8f76abfe63ed4c8cc6c34e1916d9ec Mon Sep 17 00:00:00 2001 From: galenzhao Date: Thu, 28 Jan 2021 17:36:05 +0800 Subject: [PATCH 06/10] add sign --- code.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/code.py b/code.py index ec18543..b4c5a75 100644 --- a/code.py +++ b/code.py @@ -48,7 +48,7 @@ # layer 3 ( BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, VAL_RGB, RGB_VAL, ___, - RGB_MOD, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,___,___,___, ___, + RGB_MOD, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,MACRO(4),MACRO(2),MACRO(3), ___, RGB_TOGGLE,HUE_RGB,RGB_HUE,SAT_RGB,RGB_SAT,___,___,___,___,___,___,___, ___, ___, ___, ___, ___, ___, ___, ___, ___,___,___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___ @@ -136,6 +136,10 @@ def macro_handler(dev, n, is_down): if is_down: dev.backlight.set_brightness(255) + elif n == 4: + if is_down: + print('keyboard.battery.level #{}'.format(keyboard.battery.level)) + #if is_down: # dev.send_text('You pressed macro #{}\n'.format(n)) #else: @@ -144,11 +148,11 @@ def macro_handler(dev, n, is_down): def pairs_handler(dev, n): #dev.send_text('You just triggered pair keys #{}\n'.format(n)) if n == 0: - dev.send_text('ls -alh --color\n') + dev.send_text('ls -alh\n') elif n == 1: - dev.send_text('du -sh *\n') + dev.send_text('du -sh ./*\n') elif n == 2: - dev.send_text('ifconfig; ip addr') + dev.send_text('ifconfig') keyboard.macro_handler = macro_handler From 33aba7b9fc9c3e0e499a3d571e6705df47af9f6c Mon Sep 17 00:00:00 2001 From: galenzhao Date: Mon, 8 Feb 2021 11:39:44 +0800 Subject: [PATCH 07/10] overflow after long sleep --- keyboard/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/keyboard/__init__.py b/keyboard/__init__.py index 4aea99c..9162c63 100644 --- a/keyboard/__init__.py +++ b/keyboard/__init__.py @@ -559,9 +559,16 @@ def run(self): if self.verbose: keydown_time = matrix.get_keydown_time(key) - dt = ms(matrix.time() - keydown_time) - dt2 = ms(keydown_time - last_time) - last_time = keydown_time + dt = 0 + dt2 = 0 + try: + dt = ms(matrix.time() - keydown_time) + dt2 = ms(keydown_time - last_time) + except OverflowError: + print('An exception flew by!') + finally: + last_time = keydown_time + print( "{} {} \\ {} latency {} | {}".format( key, key_name(key), hex(action_code), dt, dt2 From 6c5833dafa9e423d7168f10a9c564dbe7fedd2f2 Mon Sep 17 00:00:00 2001 From: galenzhao Date: Mon, 8 Feb 2021 15:13:45 +0800 Subject: [PATCH 08/10] custom keymap config file --- code.py | 176 ++++++++++++++++++++++++++++----------------------- my_keymap.py | 132 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+), 80 deletions(-) create mode 100644 my_keymap.py diff --git a/code.py b/code.py index b4c5a75..a65f54e 100644 --- a/code.py +++ b/code.py @@ -1,6 +1,6 @@ from keyboard import * - +import my_keymap keyboard = Keyboard() @@ -17,85 +17,18 @@ SCC = MODS_TAP(MODS(RCTRL), ';') SINS = MODS_KEY(MODS(SHIFT), INSERT) -keyboard.keymap = ( - # layer 0 - ( - ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, - TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, - LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', RSFT4, - LCTRL, LGUI, LALT, SPACE, RALT, MENU, RCTRL, L1 - ), - - # layer 1 - ( - '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, - ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, - ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, UP, ___, - ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ - ), - - # layer 2 - ( - '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, - ___, ___, ___, ___, ___, ___,HOME,PGUP, ___, ___,SINS,AUDIO_VOL_DOWN,AUDIO_VOL_UP,AUDIO_MUTE, - ___, ___, ___, ___, ___, ___,LEFT,DOWN, UP,RIGHT, ___, ___, ___, - ___, ___, ___, ___, ___, ___,PGDN,END, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, ___, ___ - ), - - # layer 3 - ( - BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, VAL_RGB, RGB_VAL, ___, - RGB_MOD, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,MACRO(4),MACRO(2),MACRO(3), ___, - RGB_TOGGLE,HUE_RGB,RGB_HUE,SAT_RGB,RGB_SAT,___,___,___,___,___,___,___, ___, - ___, ___, ___, ___, ___, ___, ___, ___,___,___, ___, ___, - ___, ___, ___, ___, ___, ___, ___, ___ - ), - - # layer 4 - ( - '`', ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, D, ___, ___, ___, ___, ___, ___, ';', ___, ___, - ___, ___, ___, ___, ___, B, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___, ___, ___ - ), - - # layer 5 - ( - ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___,MS_W_UP,MS_UL,MS_UP,MS_UR, ___, ___, ___, ___, - ___, ___, ___, ___, ___, ___,MS_BTN1,MS_LT,MS_DN,MS_RT,MS_BTN2, ___, ___, - ___, ___, ___, ___, ___, ___,MS_W_DN,MS_DL,MS_DN,MS_DR, ___, ___, - ___, ___, ___, ___, ___, ___, ___, ___ - ), -) +if my_keymap.custom_keymap and len(my_keymap.custom_keymap) > 0: + keyboard.keymap = my_keymap.custom_keymap -# Use different keymaps on different connections -# Valid keys are "USB" and "BT0"-"BT9" -# Connection not in this map will use default keymap defined above. -keyboard.profiles = { - # For example, BT8 is connected to a Mac - "USB": ( - # layer 0 - ( - ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, - TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, - LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, - LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 - ), - ), - "BT1": ( +else: + keyboard.keymap = ( # layer 0 ( ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, - LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, - LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', RSFT4, + LCTRL, LGUI, LALT, SPACE, RALT, MENU, RCTRL, L1 ), # layer 1 @@ -103,11 +36,85 @@ '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___,BOOT, ___,MACRO(1), ___, ___, UP, ___, + ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, UP, ___, ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ ), + + # layer 2 + ( + '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, + ___, ___, ___, ___, ___, ___,HOME,PGUP, ___, ___,SINS,AUDIO_VOL_DOWN,AUDIO_VOL_UP,AUDIO_MUTE, + ___, ___, ___, ___, ___, ___,LEFT,DOWN, UP,RIGHT, ___, ___, ___, + ___, ___, ___, ___, ___, ___,PGDN,END, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ + ), + + # layer 3 + ( + BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, VAL_RGB, RGB_VAL, ___, + RGB_MOD, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,MACRO(4),MACRO(2),MACRO(3), ___, + RGB_TOGGLE,HUE_RGB,RGB_HUE,SAT_RGB,RGB_SAT,___,___,___,___,___,___,___, ___, + ___, ___, ___, ___, ___, ___, ___, ___,___,___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ + ), + + # layer 4 + ( + '`', ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, D, ___, ___, ___, ___, ___, ___, ';', ___, ___, + ___, ___, ___, ___, ___, B, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ + ), + + # layer 5 + ( + ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___,MS_W_UP,MS_UL,MS_UP,MS_UR, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___,MS_BTN1,MS_LT,MS_DN,MS_RT,MS_BTN2, ___, ___, + ___, ___, ___, ___, ___, ___,MS_W_DN,MS_DL,MS_DN,MS_DR, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ + ), ) -} + +# Use different keymaps on different connections +# Valid keys are "USB" and "BT0"-"BT9" +# Connection not in this map will use default keymap defined above. +if my_keymap.profiles and len(my_keymap.profiles) > 0: + keyboard.profiles = my_keymap.profiles +else: + keyboard.profiles = { + # For example, BT8 is connected to a Mac + "USB": ( + # layer 0 + ( + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, + LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 + ), + ), + "BT1": ( + # layer 0 + ( + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, + LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 + ), + + # layer 1 + ( + '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, + ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, + ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___,BOOT, ___,MACRO(1), ___, ___, UP, ___, + ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ + ), + ) + } # add default keymap to profiles default_keymap_count = len(keyboard.keymap) @@ -154,9 +161,15 @@ def pairs_handler(dev, n): elif n == 2: dev.send_text('ifconfig') +if my_keymap.macro_handler: + keyboard.macro_handler = my_keymap.macro_handler +else: + keyboard.macro_handler = macro_handler -keyboard.macro_handler = macro_handler -keyboard.pairs_handler = pairs_handler +if my_keymap.pairs_handler: + keyboard.pairs_handler = my_keymap.pairs_handler +else: + keyboard.pairs_handler = pairs_handler # ESC(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9) 0(10) -(11) =(12) BACKSPACE(13) # TAB(27) Q(26) W(25) E(24) R(23) T(22) Y(21) U(20) I(19) O(18) P(17) [(16) ](15) \(14) @@ -168,7 +181,10 @@ def pairs_handler(dev, n): # 1. ls # 2. du # 3. ip -keyboard.pairs = [{37, 30}, {31, 20}, {19, 17}, {35, 36}, {20, 19}] +if my_keymap.pairs: + keyboard.pairs = my_keymap.pairs +else: + keyboard.pairs = [{37, 30}, {31, 20}, {19, 17}, {35, 36}, {20, 19}] # keyboard.verbose = False diff --git a/my_keymap.py b/my_keymap.py new file mode 100644 index 0000000..5fd3b91 --- /dev/null +++ b/my_keymap.py @@ -0,0 +1,132 @@ +from keyboard import * + +___ = TRANSPARENT +BOOT = BOOTLOADER +L1 = LAYER_TAP(1) +L2D = LAYER_TAP(2, D) +L3B = LAYER_TAP(3, B) +LSFT4 = LAYER_MODS(4, MODS(LSHIFT)) +RSFT4 = LAYER_MODS(4, MODS(RSHIFT)) +L5S = LAYER_TAP(5, S) + +# Semicolon & Ctrl +SCC = MODS_TAP(MODS(RCTRL), ';') +SINS = MODS_KEY(MODS(SHIFT), INSERT) + +custom_keymap = ( + # layer 0 + ( + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', RSFT4, + LCTRL, LGUI, LALT, SPACE, RALT, MENU, RCTRL, L1 + ), + + # layer 1 + ( + '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, + ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, + ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, UP, ___, + ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ + ), + + # layer 2 + ( + '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, + ___, ___, ___, ___, ___, ___,HOME,PGUP, ___, ___,SINS,AUDIO_VOL_DOWN,AUDIO_VOL_UP,AUDIO_MUTE, + ___, ___, ___, ___, ___, ___,LEFT,DOWN, UP,RIGHT, ___, ___, ___, + ___, ___, ___, ___, ___, ___,PGDN,END, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ + ), + + # layer 3 + ( + BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, VAL_RGB, RGB_VAL, ___, + RGB_MOD, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,MACRO(4),MACRO(2),MACRO(3), ___, + RGB_TOGGLE,HUE_RGB,RGB_HUE,SAT_RGB,RGB_SAT,___,___,___,___,___,___,___, ___, + ___, ___, ___, ___, ___, ___, ___, ___,___,___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ + ), + + # layer 4 + ( + '`', ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, D, ___, ___, ___, ___, ___, ___, ';', ___, ___, + ___, ___, ___, ___, ___, B, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ + ), + + # layer 5 + ( + ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___,MS_W_UP,MS_UL,MS_UP,MS_UR, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___,MS_BTN1,MS_LT,MS_DN,MS_RT,MS_BTN2, ___, ___, + ___, ___, ___, ___, ___, ___,MS_W_DN,MS_DL,MS_DN,MS_DR, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ + ), +) + +profiles = { + # For example, BT8 is connected to a Mac + "USB": ( + # layer 0 + ( + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, + LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 + ), + ), + "BT1": ( + # layer 0 + ( + ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, + TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', + CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, + LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 + ), + + # layer 1 + ( + '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, + ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, + ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___,BOOT, ___,MACRO(1), ___, ___, UP, ___, + ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ + ), + ) +} + +def macro_handler(dev, n, is_down): + if n == 2: + if is_down: + dev.backlight.set_brightness(0) + + elif n == 3: + if is_down: + dev.backlight.set_brightness(255) + + #elif n == 4: + # if is_down: + # print('keyboard.battery.level #{}'.format(keyboard.battery.level)) + + #if is_down: + # dev.send_text('You pressed macro #{}\n'.format(n)) + #else: + # dev.send_text('You released macro #{}\n'.format(n)) + +def pairs_handler(dev, n): + #dev.send_text('You just triggered pair keys #{}\n'.format(n)) + if n == 0: + dev.send_text('ls -alh\n') + elif n == 1: + dev.send_text('du -sh ./*\n') + elif n == 2: + dev.send_text('ifconfig') + +pairs = [{37, 30}, {31, 20}, {19, 17}, {35, 36}, {20, 19}] From 6e84805e30e99b7fa9ec75a73b0e85f66bc54c38 Mon Sep 17 00:00:00 2001 From: galenzhao Date: Tue, 9 Feb 2021 16:34:45 +0800 Subject: [PATCH 09/10] rollback code.py to default keymap --- code.py | 68 ++++++++++++++------------------------------ keyboard/__init__.py | 9 +++++- 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/code.py b/code.py index a65f54e..eb4550f 100644 --- a/code.py +++ b/code.py @@ -26,9 +26,9 @@ ( ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, + CAPS, A, S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, LSFT4, Z, X, C, V, L3B, N, M, ',', '.', '/', RSFT4, - LCTRL, LGUI, LALT, SPACE, RALT, MENU, RCTRL, L1 + LCTRL, LGUI, LALT, SPACE, RALT, MENU, L1, RCTRL ), # layer 1 @@ -36,8 +36,8 @@ '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, UP, ___, - ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ + ___, ___, ___, ___, ___,BOOT, ___,MACRO(0), ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ ), # layer 2 @@ -51,10 +51,10 @@ # layer 3 ( - BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, VAL_RGB, RGB_VAL, ___, - RGB_MOD, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,MACRO(4),MACRO(2),MACRO(3), ___, + BT_TOGGLE,BT1,BT2, BT3,BT4,BT5,BT6,BT7, BT8, BT9, BT0, ___, ___, ___, + RGB_MOD, ___, ___, ___, ___, ___,___,USB_TOGGLE,___,___,___,___,___, ___, RGB_TOGGLE,HUE_RGB,RGB_HUE,SAT_RGB,RGB_SAT,___,___,___,___,___,___,___, ___, - ___, ___, ___, ___, ___, ___, ___, ___,___,___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___,VAL_RGB,RGB_VAL, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___ ), @@ -77,6 +77,7 @@ ), ) + # Use different keymaps on different connections # Valid keys are "USB" and "BT0"-"BT9" # Connection not in this map will use default keymap defined above. @@ -85,24 +86,14 @@ else: keyboard.profiles = { # For example, BT8 is connected to a Mac - "USB": ( - # layer 0 - ( - ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, - TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, - LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, - LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 - ), - ), - "BT1": ( + "BT8": ( # layer 0 ( ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '-', '=', BACKSPACE, TAB, Q, W, E, R, T, Y, U, I, O, P, '[', ']', '|', - CAPS, A, L5S, L2D, F, G, H, J, K, L, SCC, '"', ENTER, - LSHIFT,Z, X, C, V, L3B, N, M, ',', '.', '/', RSHIFT, - LCTRL, LALT, LGUI, SPACE, MENU, RALT, RCTRL, L1 + CAPS, A, S, D, F, G, H, J, K, L, SCC, '"', ENTER, + LSHIFT,Z, X, C, V, B, N, M, ',', '.', '/', RSHIFT, + LCTRL, LALT, LGUI, SPACE, MENU, RALT, L1, RCTRL ), # layer 1 @@ -110,12 +101,13 @@ '`', F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, DEL, ___, ___, UP, ___, ___, ___, ___, ___, ___, ___,SUSPEND,___,___,___, ___,LEFT,DOWN,RIGHT,___, ___, ___, ___, ___, ___, ___, ___, ___, - ___, ___, ___, ___, ___,BOOT, ___,MACRO(1), ___, ___, UP, ___, - ___, ___, ___, ___, LEFT, DOWN, RIGHT, ___ + ___, ___, ___, ___, ___,BOOT, ___,MACRO(1), ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, ___ ), ) } + # add default keymap to profiles default_keymap_count = len(keyboard.keymap) for i in keyboard.profiles.keys(): @@ -135,31 +127,15 @@ def macro_handler(dev, n, is_down): - if n == 2: - if is_down: - dev.backlight.set_brightness(0) + if is_down: + dev.send_text('You pressed macro #{}\n'.format(n)) + else: + dev.send_text('You released macro #{}\n'.format(n)) - elif n == 3: - if is_down: - dev.backlight.set_brightness(255) - - elif n == 4: - if is_down: - print('keyboard.battery.level #{}'.format(keyboard.battery.level)) +def pairs_handler(dev, n): + dev.send_text('You just triggered pair keys #{}\n'.format(n)) - #if is_down: - # dev.send_text('You pressed macro #{}\n'.format(n)) - #else: - # dev.send_text('You released macro #{}\n'.format(n)) -def pairs_handler(dev, n): - #dev.send_text('You just triggered pair keys #{}\n'.format(n)) - if n == 0: - dev.send_text('ls -alh\n') - elif n == 1: - dev.send_text('du -sh ./*\n') - elif n == 2: - dev.send_text('ifconfig') if my_keymap.macro_handler: keyboard.macro_handler = my_keymap.macro_handler @@ -184,7 +160,7 @@ def pairs_handler(dev, n): if my_keymap.pairs: keyboard.pairs = my_keymap.pairs else: - keyboard.pairs = [{37, 30}, {31, 20}, {19, 17}, {35, 36}, {20, 19}] + keyboard.pairs = [{35, 36}, {20, 19}] # keyboard.verbose = False diff --git a/keyboard/__init__.py b/keyboard/__init__.py index 9162c63..b22ec8c 100644 --- a/keyboard/__init__.py +++ b/keyboard/__init__.py @@ -193,7 +193,14 @@ def get_key_sequence_info(self, start, end): else: desc += " / " t1 = matrix.get_keyup_time(key) - dt = matrix.ms(t1 - t0) + + dt = 0 + try: + dt = matrix.ms(t1 - t0) + + except OverflowError: + print('An exception flew by!') + t0 = t1 t.append(dt) From f57b5016c2c6e19ec3aab9e1eeedcad714ca8e50 Mon Sep 17 00:00:00 2001 From: galenzhao Date: Tue, 9 Mar 2021 15:08:48 +0800 Subject: [PATCH 10/10] disable pairkey --- code.py | 19 ++++++------------- my_keymap.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/code.py b/code.py index eb4550f..2fc7dec 100644 --- a/code.py +++ b/code.py @@ -124,7 +124,8 @@ #print(keyboard.profiles) - +print('keyboard.keymap = #{}'.format(len(keyboard.keymap))) +print('keyboard.profiles = #{}'.format(len(keyboard.profiles))) def macro_handler(dev, n, is_down): if is_down: @@ -147,21 +148,13 @@ def pairs_handler(dev, n): else: keyboard.pairs_handler = pairs_handler -# ESC(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9) 0(10) -(11) =(12) BACKSPACE(13) -# TAB(27) Q(26) W(25) E(24) R(23) T(22) Y(21) U(20) I(19) O(18) P(17) [(16) ](15) \(14) -# CAPS(28) A(29) S(30) D(31) F(32) G(33) H(34) J(35) K(36) L(37) ;(38) "(39) ENTER(40) -#LSHIFT(52) Z(51) X(50) C(49) V(48) B(47) N(46) M(45) ,(44) .(43) /(42) RSHIFT(41) -# LCTRL(53) LGUI(54) LALT(55) SPACE(56) RALT(57) MENU(58) Fn(59) RCTRL(60) - # Pairs: J & K, U & I -# 1. ls -# 2. du -# 3. ip -if my_keymap.pairs: - keyboard.pairs = my_keymap.pairs -else: +if my_keymap.pairs is None: keyboard.pairs = [{35, 36}, {20, 19}] +else: + keyboard.pairs = my_keymap.pairs # keyboard.verbose = False +print('keyboard.pairs = #{}'.format(len(keyboard.pairs))) keyboard.run() diff --git a/my_keymap.py b/my_keymap.py index 5fd3b91..3f7a178 100644 --- a/my_keymap.py +++ b/my_keymap.py @@ -129,4 +129,14 @@ def pairs_handler(dev, n): elif n == 2: dev.send_text('ifconfig') -pairs = [{37, 30}, {31, 20}, {19, 17}, {35, 36}, {20, 19}] +# ESC(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9) 0(10) -(11) =(12) BACKSPACE(13) +# TAB(27) Q(26) W(25) E(24) R(23) T(22) Y(21) U(20) I(19) O(18) P(17) [(16) ](15) \(14) +# CAPS(28) A(29) S(30) D(31) F(32) G(33) H(34) J(35) K(36) L(37) ;(38) "(39) ENTER(40) +#LSHIFT(52) Z(51) X(50) C(49) V(48) B(47) N(46) M(45) ,(44) .(43) /(42) RSHIFT(41) +# LCTRL(53) LGUI(54) LALT(55) SPACE(56) RALT(57) MENU(58) Fn(59) RCTRL(60) + +# 1. ls +# 2. du +# 3. ip +#pairs = [{37, 30}, {31, 20}, {19, 17}, {35, 36}, {20, 19}] +pairs = []