Controlling i3 Workspaces with an External USB Numpad #6049
djarum-black
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Title: Controlling i3 Workspaces and Executing Shell Commands with an External USB Numpad
Hello everyone,
I've been working on a Python script that allows me to use an external generic USB numpad to control various functions in i3 and execute shell commands. I thought I'd share it here in case anyone else finds it useful.
It's configured using a YAML file, which maps keys on the numpad to commands or functions.
You also have the ability to set window-specific shortcuts. These are only activated when a specific window is in focus. The window matching can be done based on the start, end, or any part of the window name, or an exact match.
Here's an example of the configuration file
shortcuts.yaml
:In this example, pressing the keys from
KEY_KP1
toKEY_KP9
andKEY_KP0
on the numpad will switch to workspaces 1 to 10 respectively. TheKEY_KPMINUS
key will perform different actions based on the active window's name.You can run any command that can be executed in a shell. The command just needs to be specified as a list of strings, where each string is a part of the command. For example, if you want to run the command
ls -l
, you would add it to theshortcuts.yaml
file like this:In this case, when you press the
KEY_KPPLUS
key on your numpad, thels -l
command will be executed. The output of the command will be displayed in the terminal where you are running thenumpad.py
script.To run the script, you'll need to install the required Python packages. You can do this by running
pip install -r requirements.txt
in your terminal. Then, simply run the script withpython numpad.py
.You can find the Python script and the configuration file in my GitHub Gist.
I hope someone finds this useful.
Beta Was this translation helpful? Give feedback.
All reactions