Skip to content

Commit 99be278

Browse files
committed
Added ability to adjust tap and pair key delays
1 parent ed762e7 commit 99be278

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

keyboard/__init__.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,6 @@ def reset_into_bootloader():
8282
microcontroller.reset()
8383

8484

85-
def is_tapped(matrix, key):
86-
"""Check if the key is tapped (press & release quickly)"""
87-
n = len(matrix)
88-
if n == 0:
89-
n = matrix.wait(500 - matrix.ms(matrix.time() - matrix.get_keydown_time(key)))
90-
target = key | 0x80
91-
if n == 1:
92-
if target == matrix.view(0):
93-
return True
94-
else:
95-
n = matrix.wait(
96-
200 - matrix.ms(matrix.time() - matrix.get_keydown_time(key))
97-
)
98-
if n == 2 and target == matrix.view(1):
99-
# Fast typing: A down, B down, A up, B up
100-
return True
101-
102-
return False
103-
10485

10586
class Device:
10687
def __init__(self, kbd):
@@ -157,6 +138,8 @@ def __init__(self, keymap=KEYMAP, pairs=(), verbose=True):
157138
self.uid = microcontroller.cpu.uid * 2
158139
self.usb_status = 0
159140
self.leds = None
141+
self.tap_delay = 500
142+
self.pair_delay = 10
160143

161144
self._current_conn = ""
162145

@@ -264,6 +247,25 @@ def stop_advertising(self):
264247
except Exception as e:
265248
print(e)
266249

250+
def is_tapped(self, matrix, key):
251+
"""Check if the key is tapped (press & release quickly)"""
252+
n = len(matrix)
253+
if n == 0:
254+
n = matrix.wait(self.tap_delay - matrix.ms(matrix.time() - matrix.get_keydown_time(key)))
255+
target = key | 0x80
256+
if n == 1:
257+
if target == matrix.view(0):
258+
return True
259+
else:
260+
n = matrix.wait(
261+
200 - matrix.ms(matrix.time() - matrix.get_keydown_time(key))
262+
)
263+
if n == 2 and target == matrix.view(1):
264+
# Fast typing: A down, B down, A up, B up
265+
return True
266+
267+
return False
268+
267269
def change_bt(self, n):
268270
if self.ble.connected:
269271
for c in self.ble.connections:
@@ -396,7 +398,7 @@ def run(self):
396398
key = matrix.view(0)
397399
if key < 0x80 and key in self.pair_keys:
398400
n = matrix.wait(
399-
10 - ms(matrix.time() - matrix.get_keydown_time(key))
401+
self.pair_delay - ms(matrix.time() - matrix.get_keydown_time(key))
400402
)
401403

402404
if n >= 2:
@@ -438,7 +440,7 @@ def run(self):
438440
self.press(*keycodes)
439441
elif kind < ACT_USAGE:
440442
# MODS_TAP
441-
if is_tapped(matrix, key):
443+
if self.is_tapped(matrix, key):
442444
log("TAP")
443445
keycode = action_code & 0xFF
444446
keys[key] = keycode
@@ -462,7 +464,7 @@ def run(self):
462464
keycodes = mods_to_keycodes(mods)
463465
self.press(*keycodes)
464466
self.layer_mask |= mask
465-
elif is_tapped(matrix, key):
467+
elif self.is_tapped(matrix, key):
466468
log("TAP")
467469
keycode = action_code & 0xFF
468470
if keycode == OP_TAP_TOGGLE:

0 commit comments

Comments
 (0)