LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   executing scripts when pressing keyboard hotkeys (https://www.linuxquestions.org/questions/slackware-14/executing-scripts-when-pressing-keyboard-hotkeys-4175433373/)

danielldaniell 10-21-2012 01:18 PM

executing scripts when pressing keyboard hotkeys
 
Hi!

I have a Dell Inspiron laptop on which I can not use the LCD brightness function keys.
My question is more of a general inquiry as to how to use eg. those keys, and bind
some scripts to them.
The keys are recognized with xev(1), they are reported as XF86MonBrightnessUp and
XF86MonBrightnessDown. At least under Xorg I could use these keys, if I could use
some daemon which listens to these keypresses. I remember I used hotkeyd [1] before but it seems unmaintained.
I'm not using any common desktop environment, so there isn't any configurator for
these kind of things. On the other hand, it would be awesome if the solution would also work on the console.
This would not only be useful for the brightness keys, but any other otherwise "unusable" hotkeys on the keyboard.

Any advice would be appreciated,
Thanks

[1] - http://hotkeyd.sourceforge.net/

shahinism 10-22-2012 08:12 AM

Recently I found an awesome tool that I think can help you a lot. It's name is xdotool. But anyway it depends on your X Server.

Stephen Morgan 10-22-2012 09:21 AM

Odd, I always assumed those keys worked directly with the kernel, I've certainly never had to configure them on any system or with any distro.

Even if you're not using KDE or XFCE or one of those, most WMs will have some sort of config file to allow you to bind hotkeys to commands. ~/.fluxbox/keys with fluxbox, ~/.ratpoisonrc with ratpoison, and so on. Maybe you can use Xmodmap to do it directly through the X server so it will work with any DE or WM. You'd just have to tell it react to that keypress by changing the value for your backlight brightness, which I believe is in some file in /sys or /proc. Certainly used to be.

If you want it to work with the console, you could probably use inputrc, assuming you're using bash or anything remotely similar, and bind the key to a command there, if it's being read by the console. That won't work with keys or combinations already commandeered by other things, like Alt-F1. On my system the brightness controls are Fn+arrow keys, you could probably bind Alt-arrows if you wanted, using inputrc. Of course that'll only work at the prompt, not in other cli programmes.

Maybe something with loadkeys or udev.

danielldaniell 10-22-2012 03:01 PM

Quote:

Originally Posted by Stephen Morgan (Post 4812188)
Odd, I always assumed those keys worked directly with the kernel, I've certainly never had to configure them on any system or with any distro.

With some models they actually work. The brightness keys are working during the BIOS boot and even in LILO. After the kernel boots, they just produce '@' characters.

Quote:

Originally Posted by Stephen Morgan (Post 4812188)
Even if you're not using KDE or XFCE or one of those, most WMs will have some sort of config file to allow you to bind hotkeys to commands. ~/.fluxbox/keys with fluxbox, ~/.ratpoisonrc with ratpoison, and so on. Maybe you can use Xmodmap to do it directly through the X server so it will work with any DE or WM. You'd just have to tell it react to that keypress by changing the value for your backlight brightness, which I believe is in some file in /sys or /proc. Certainly used to be.

Okay, I'll try to look into it deeper :)

Quote:

Originally Posted by Stephen Morgan (Post 4812188)
If you want it to work with the console, you could probably use inputrc, assuming you're using bash or anything remotely similar, and bind the key to a command there, if it's being read by the console. That won't work with keys or combinations already commandeered by other things, like Alt-F1. On my system the brightness controls are Fn+arrow keys, you could probably bind Alt-arrows if you wanted, using inputrc. Of course that'll only work at the prompt, not in other cli programmes.

Well, on a second thought, it won't be too much of a trouble to use the scripts directly in the command line; that is at least close to a full solution.


Thanks for the insights and the tips!

danielldaniell 10-22-2012 03:03 PM

Quote:

Originally Posted by shahinism (Post 4812144)
Recently I found an awesome tool that I think can help you a lot. It's name is xdotool. But anyway it depends on your X Server.

Thanks for the pointer. I'm afraid it doesn't quite do what I need here, but nevertheless it is a very useful tool. I could definitely use it in the future for other purposes.


All times are GMT -5. The time now is 04:09 AM.