2

I know its possible to assign a Hotkey to run a Python script by configuring the openbox/lxde-pi-rc.xml. However this Hotkey then only works under X11 GUI. What I would need is a hotkey that works even if the system is not booted into the GUI but running a different Program.

I tried a number of ways (most of which I don't remember anymore now) but the big problem always seemed to be that the Program I am running in the Foreground (XCSoar, a glider navigation program) seems to prevent letting keystrokes be passed "through" it to the system in the background.
I imagine the same Problem would occur with most other Programs.

Does anyone know if it is possible to assign a Key (Preferably F12) to always run a python script no matter what other Program might be running at that time?

Boooing
  • 23
  • 4

1 Answers1

1

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.

Aurora0001
  • 6,357
  • 3
  • 25
  • 39