I want to connect a batch script to a shortcut. When I bind it under System Settings > Keyboard > Shortcuts it works with every key, except my brightness keys from my external Apple keyboard.
The brightness keys are recognized in showkey with the keycode 224 and 225.
xev output:
FocusOut event, serial 41, synthetic NO, window 0x4000001,
mode NotifyGrab, detail NotifyAncestor
FocusIn event, serial 41, synthetic NO, window 0x4000001,
mode NotifyUngrab, detail NotifyAncestor
KeymapNotify event, serial 41, synthetic NO, window 0x0,
keys: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Any suggestions what I can do?
Best Answer
Solution using halevt
According to the man pages
halevt
is a generic handler for HAL events. It is deprecated and replaced byudev
, but since I don't know enough aboutudev
I will give ahalevt
solution.EDIT: after some serious sweat, I managed to do this in
udev
. See my other answer.I will use
vim
to edit files, but if you don't knowvim
you can replace it bynano
orgedit
.Installing halevt
Determining which events you want to bind to a script
Stop the
halevt
daemon which is already running:Now see if
halevt
can recognize the events of the keys you want to use, start the listener:Now press the function key on your keyboard you want to bind the script to. I know that the OP wants to get his brightness keys working, so let's go with that. The output for the brightness keys should look something like this:
You can see that the
brightness-down
andbrightness-up
events are transmitted.Bind the event to a script
Now edit the file
/etc/halevt/halevt.xml
:and add the following lines ( I did it at the bottom, just before
</halevt:Configuration>
):where of course you should change
value
to the event that you got from the listener, andexec
by the command you want to execute.Give the halevt user permission to do the command or script
Since the
halevt
daemon is run as thehalevt
user you have to give it permission to do what you specified inexec
.Run (remember to replace
vim
by your editor of choice)and add the following lines at the bottom
and save and quit.
Make sure your script is executable
Start the halevt daemon again
And it should be working!