forked from KMKfw/kmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stock.py
146 lines (92 loc) · 3.34 KB
/
stock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from time import sleep
def passthrough(key, keyboard, *args, **kwargs):
return keyboard
def default_pressed(key, keyboard, KC, coord_int=None, *args, **kwargs):
keyboard.hid_pending = True
keyboard.keys_pressed.add(key)
return keyboard
def default_released(key, keyboard, KC, coord_int=None, *args, **kwargs): # NOQA
keyboard.hid_pending = True
keyboard.keys_pressed.discard(key)
return keyboard
def reset(*args, **kwargs):
import microcontroller
microcontroller.reset()
def reload(*args, **kwargs):
import supervisor
supervisor.reload()
def bootloader(*args, **kwargs):
import microcontroller
microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER)
microcontroller.reset()
def debug_pressed(key, keyboard, KC, *args, **kwargs):
if keyboard.debug_enabled:
print('DebugDisable()')
else:
print('DebugEnable()')
keyboard.debug_enabled = not keyboard.debug_enabled
return keyboard
def gesc_pressed(key, keyboard, KC, *args, **kwargs):
GESC_TRIGGERS = {KC.LSHIFT, KC.RSHIFT, KC.LGUI, KC.RGUI}
if GESC_TRIGGERS.intersection(keyboard.keys_pressed):
# First, release GUI if already pressed
keyboard._send_hid()
# if Shift is held, KC_GRAVE will become KC_TILDE on OS level
keyboard.keys_pressed.add(KC.GRAVE)
keyboard.hid_pending = True
return keyboard
# else return KC_ESC
keyboard.keys_pressed.add(KC.ESCAPE)
keyboard.hid_pending = True
return keyboard
def gesc_released(key, keyboard, KC, *args, **kwargs):
keyboard.keys_pressed.discard(KC.ESCAPE)
keyboard.keys_pressed.discard(KC.GRAVE)
keyboard.hid_pending = True
return keyboard
def bkdl_pressed(key, keyboard, KC, *args, **kwargs):
BKDL_TRIGGERS = {KC.LGUI, KC.RGUI}
if BKDL_TRIGGERS.intersection(keyboard.keys_pressed):
keyboard._send_hid()
keyboard.keys_pressed.add(KC.DEL)
keyboard.hid_pending = True
return keyboard
# else return KC_ESC
keyboard.keys_pressed.add(KC.BKSP)
keyboard.hid_pending = True
return keyboard
def bkdl_released(key, keyboard, KC, *args, **kwargs):
keyboard.keys_pressed.discard(KC.BKSP)
keyboard.keys_pressed.discard(KC.DEL)
keyboard.hid_pending = True
return keyboard
def sleep_pressed(key, keyboard, KC, *args, **kwargs):
sleep(key.meta.ms / 1000)
return keyboard
def uc_mode_pressed(key, keyboard, *args, **kwargs):
keyboard.unicode_mode = key.meta.mode
return keyboard
def hid_switch(key, keyboard, *args, **kwargs):
keyboard.hid_type, keyboard.secondary_hid_type = (
keyboard.secondary_hid_type,
keyboard.hid_type,
)
keyboard._init_hid()
return keyboard
def ble_refresh(key, keyboard, *args, **kwargs):
from kmk.hid import HIDModes
if keyboard.hid_type != HIDModes.BLE:
return keyboard
keyboard._hid_helper.stop_advertising()
keyboard._hid_helper.start_advertising()
return keyboard
def ble_disconnect(key, keyboard, *args, **kwargs):
from kmk.hid import HIDModes
if keyboard.hid_type != HIDModes.BLE:
return keyboard
keyboard._hid_helper.clear_bonds()
return keyboard
def any_pressed(key, keyboard, *args, **kwargs):
from random import randint
key.code = randint(4, 56)
default_pressed(key, keyboard, *args, **kwargs)