4.8 KiB
Overview:
This is a project I made to control a home theater PC (HTPC) with a pepper jobs remote control with customized commands on the buttons on a per-app basis using bash scripts.
The pepper jobs remote buttons are mapped to common windows shortcuts. Depending on your desktop environment some of these will work as generic shortcuts in linux out of the box, but my goal was to make the buttons behave differently depending on which app is active. For example: when firefox is open to the site youtube.com, pressing the search button will type "/" to move focus to the search bar at the top of the screen and type "control+a" to select all then type "BackSpace" to clear any text in it so you can flip the remote and start typing; In kodi the same button will open a kodi search menu by executing: kodi-send --action="VideoLibrary.Search".
Parts list:
Pulse eight usb-hdmi-cec-adapter
The computer could be anything, the hardware requirements are what you want to do with it.
The cec adapter is optional, but allows the computer to turn the tv on and off via software which is mapped to the power button on the remote. It is also not necessary if running on a raspberry pi since cec is built into the hardware.
OS:
I am running endeavouros on the computer, but this could be any linux distro with the following software installed.
Software:
required:
xorg xfce4 xdotool wmctrl
optional:
libcec # for cec controls kodi freetube spotify # other apps etc...
How it works:
- The button shortcuts are mapped in xfce to run the buttons.sh script when pressed.
- buttons.sh runs get_active_window.sh to find what program is active.
- It then looks for this program in the scripts in the app folder and inits it if it finds it.
- After that it will look for the button that was pressed in the app script that was just loaded
- If it finds that button in the app script it will run the code in the method
- If it does not find the button in there it will look for the button in apps/default_commands.sh and run it if it finds it.
Notes:
My goal with this project was to make it as easy as possible to hop in and modify how any button works in any program. In order to add a new program you make a new sh file file in /apps with the name returned by get_active_window.sh. In that file make a method with the programed name (see list below) of any button that you want to remap with the code you want to run.
For an example of further segementing button presses in an app, ie firefox has different methods when on youtube.com vs pbs.org, see: get_active_window.sh and apps/firefox.sh
find_or_open.sh will check running programs, if what it is looking for is running already it will give it focus, if it is not it will launch the program.
When possible I will use commands that will preform the desired actions in the specified software. If that is not possible instead I simulate key presses using xdotool to use keyboard shortcuts provided by the application.
debug output goes to both the debug file and stdout when the buttons.sh script is run. This way troubleshooting can happen both on the command line when manually running buttons.sh and also in the debug file when testing buttons on the remote.
There is an init.sh script that will copy the xfce4 shortcuts to the .config folder as well as a kodi config file. It also disables the XF86PowerOff button in Xorg. Without this the power button caused the remote to lock up until the system was rebooted even if XF86PowerOff was set to do nothing in xfce. After this the power button can be repurposed to run the cec.sh script to turn the tv on and off.
some buttons are left as globals, ie, close is alt+f4, tab is left and in xfce config, cycle_windows_key is remapped to just tab instead of standard alt + tab, so this button can be used to cycle through open programs.
Button Names:
# if no comment these name correspond to the words on the remote sleep, # power main, notification, search, settings, action_center, file_explorer, desktop, refresh, browser, task_manager, move_up, play, forward, back, fast_forward, rewind split_up, # bottom row left split_down, # bottom row left middle split_left, # bottom row right middle split_right, # bottom row right
Future Plans:
In the future I plan to migrate this project to Nixos