-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard_linux.py
83 lines (65 loc) · 2.07 KB
/
keyboard_linux.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
from pmk import PMK
from pmk.platform.rgbkeypadbase import RGBKeypadBase as Hardware
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
import random
import utils
keyboard = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(keyboard)
## define functions to link up with keys. Use decorators to indicate type
@utils.launcher
def launch_vscode():
"""
Requires powertoys on windows, or maping alt + space to launcher
"""
keyboard.send(Keycode.CONTROL, Keycode.SPACE)
keyboard.send(Keycode.DELETE)
layout.write("Code")
utils.sleep(0.1)
keyboard.send(Keycode.ENTER)
@utils.launcher
def launch_terminal():
keyboard.send(Keycode.CONTROL, Keycode.SPACE)
keyboard.send(Keycode.DELETE)
layout.write("Terminal")
utils.sleep(0.1)
keyboard.send(Keycode.ENTER)
@utils.macro
def run_update():
keyboard.send(Keycode.CONTROL, Keycode.SPACE)
keyboard.send(Keycode.DELETE)
layout.write("Terminal")
utils.sleep(0.1)
keyboard.send(Keycode.ENTER)
utils.sleep(0.5)
layout.write("sudo apt update && sudo apt upgrade")
utils.sleep(0.1)
keyboard.send(Keycode.ENTER)
@utils.macro
def launch_nerd_youtube():
keyboard.send(Keycode.WINDOWS, Keycode.R)
utils.sleep(0.1)
layout.write("firefox https://www.youtube.com/c/JeffGeerling")
keyboard.send(Keycode.ENTER)
@utils.emergency_exit
def zoom_nuke():
keyboard.send(Keycode.LEFT_ALT, Keycode.Q)
@utils.noop
def noop():
print("This key does nothing!")
def run_linux(pmk, hardware):
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
print(alphabet)
keycodes = {
"win": Keycode.WINDOWS}
for letter in alphabet:
keycodes[letter] = layout.keycodes(letter)[0]
keymap = { k : noop for k in pmk.keys}
keymap[pmk.keys[0]] = launch_vscode
keymap[pmk.keys[1]] = launch_terminal
keymap[pmk.keys[2]] = run_update
keymap[pmk.keys[3]] = zoom_nuke
keymap[pmk.keys[4]] = launch_nerd_youtube
return keymap