esekeyd is an alternative to using keyboard shortcuts in Openbox, which will work even if X.Org isn't running. As noted in the Debian repositories:
ESE Key Daemon is a multimedia keyboard daemon for Linux. With the 2.6 kernel series it can also handle remote controls, as they are presented as keyboards. No kernel patch is required. It is a userspace program that pools /dev/input/event? interfaces for incoming keyboard key presses.
It is rather poorly documented, unfortunately, but I gave it a try and it does indeed work well.
It can be installed with:
sudo apt-get install esekeyd
You will then need to figure out which device file is your keyboard. There are several ways to do this, as explained on Stack Overflow, but I found the brute force method to be the best. Run:
sudo keytest /dev/input/event0
... and press a few keys. If you press your left Alt, and the program prints LEFTALT
, good. If it just prints a strange character combination, or nothing at all, press Ctrl+C, change event0
to event1
and repeat. Keep going (replace event1
with event2
and so forth, if that doesn't work) until you find the input that does work. Once you do find it, remember which device file you need.
Then run:
sudo learnkeys /etc/esekeyd.conf /dev/input/eventX
... and press F12.
Now, esekeyd
will create the configuration file you need. You then need to edit it with your editor of choice (mine's nano, so I'd run sudo nano /etc/esekeyd.conf
).
You'll see a line like this:
#F12(press):
Delete the #
, and add your desired command directly after the :
(no spaces!). Your new line might look something like this:
F12(press):/home/user/test_script.sh
Then, save (it's Ctrl+O then Enter for nano).
After that, you simply need to run esekeyd
with the configuration file you've just created:
sudo esekeyd /etc/esekeyd.conf /dev/input/eventX
It won't automatically start at boot, so you'll need to set that up yourself, if you need it. It's up to you how, and any of those methods should work just fine.
The learnkeys worked and it added F12 to the esekeyd.conf file.
– Boooing Jan 08 '18 at 08:41Then I edited the exekeyd.conf and removed hastag and added the command so the line now says:
F12(press):python /home/pi/test.py
Then I rebooted and tried it out and it only shows the ~ in the command-line when I press F12. Also tried it with other buttons and commands..
Any idea what could still be wrong?
F10(press):reboot
F11(press):xcsoar
F12(press):python /home/pi/test4.py
reboot and running xcsoar work but F12 does nothing but display a ~
– Boooing Jan 08 '18 at 09:09Any ideas?
python /home/pi/test4.py
work normally in a command prompt? 2. Does running a different command forF12(press)
work (e.g. runxcsoar
on F12 press). If running a different command works, then the issue is probably your script. If it doesn't, then the issue is something to do with esekeyd's F12 binding. If that's the case, running your Python script on F10 or F11 might work. – Aurora0001 Jan 08 '18 at 16:12My new problem is: From the Terminal I press F12 and it runs camera.py just fine. However when I start XCSoar and then press F12 nothing happens - instead it only displays the 5-second webcam feed after I closed XCSoar. For example I press F12 three times while XCSoar is running and nothing happens. But once I close XCSoar the 5-second webcam feed pops up three times.. Any idea what could cause this? – Boooing Jan 09 '18 at 08:56