Skip to content

Instantly share code, notes, and snippets.

@shm-sl
Created July 3, 2020 10:56
Show Gist options
  • Save shm-sl/547afb681386fef6f1dbc7a5aaa21851 to your computer and use it in GitHub Desktop.
Save shm-sl/547afb681386fef6f1dbc7a5aaa21851 to your computer and use it in GitHub Desktop.
2nd Keyboard for Macros
#!/bin/bash
# Syntax: ./activate-window.sh <Window Title> <Window Command to Run>
wmctrl -a "$1"
if [ $? != 0 ]
then
$? = 0
$2
wmctrl -a "$1"
fi
# https://www.reddit.com/r/linux/comments/8geyru/diy_linux_macro_board
import os
from evdev import InputDevice, categorize, ecodes
dev = InputDevice('/dev/input/by-id/usb-SEM_USB_Keyboard-event-kbd') # change this to your input device
dev.grab()
actwin = '/home/sl/2nd-keyboard/activate-window.sh '
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
key = categorize(event)
if key.keystate == key.key_down:
print(key.keycode)
# row 1
if key.keycode == 'KEY_TAB':
os.system(actwin + 'atom atom')
# row 2
if key.keycode == 'KEY_NUMLOCK':
os.system(actwin + 'mattermost mattermost')
if key.keycode == 'KEY_KPSLASH':
os.system(actwin + 'dolphin dolphin')
if key.keycode == 'KEY_KPASTERISK':
os.system('xdotool key ctrl+shift+Tab')
if key.keycode == 'KEY_BACKSPACE':
os.system('xdotool key ctrl+Tab')
# row 3
if key.keycode == 'KEY_KP7':
os.system(actwin + '"Firefox Developer Edition" /opt/firefox-dev/firefox')
os.system('xdotool key alt+1')
if key.keycode == 'KEY_KP9':
os.system(actwin + 'kcalc kcalc')
if key.keycode == 'KEY_KPMINUS': # bell
os.system(actwin + '"VLC media player" vlc')
# row 5
if key.keycode == 'KEY_KP1':
os.system(actwin + '"LibreOffice Calc" "libreoffice --calc"') # FIXME: focus not working
if key.keycode == 'KEY_KP2':
os.system(actwin + '"Chromium" "chromium-browser %U --disk-cache-dir=/dev/null"')
if key.keycode == 'KEY_KP3':
os.system(actwin + '"Mozilla Firefox" firefox')
# row 6
if key.keycode == 'KEY_KP0':
os.system(actwin + '"Firefox Developer Edition" /opt/firefox-dev/firefox')
os.system('xdotool key alt+3')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment