I have a fresh install of 16.04 on a new Levono Ideapad 500S. I've been trying to make the brightness keys work and have finally managed to hook up the brightness up key to work as expected.

However, I need to change the keycode of my brightness down key in order for it to work, but setkeycodes does not seem to be doing anything.

Running showkey and pressing the brightness down button thrice gives me:

$ sudo showkey -s
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]

press any key (program terminates 10s after last keypress)...
0xe0 0x6f 0xe0 0xef 
0xe0 0x6f 0xe0 0xef 
0xe0 0x6f 0xe0 0xef 

which led me to believe that the scancode of it is e06f. However, running sudo setkeycodes e06f 224 and then running showkey -k still shows the old key code (which was 112).

Can setkeycodes not override an already set keycode from some other source? If so, how can I change the brightness down key's keycode.


setkeycodes will change the key mappings at kernel level itself. Here there is an issue in understanding the scan code values. For key press it's: 0x6f and for release it's :0xef. So the command you need to run is :

sudo setkeycodes 6fef 224 

This will change the mapping to the desired one.

| improve this answer | |

It took me a little bit to figure out the gotcha with trying to do mappings on a PS/2 keyboard with showkey and setkeycodes.

As hinted at on the man page for setkeycodes, there is a problem that affects tools that report scan codes such as showkey -s in the sense that they don't show the actual scan codes that are appropriate input for setkeycodes:

In 2.6 kernels raw mode, or scancode mode, is not very raw at all.

After relying on the output of showkey -s for a bit and noticing my mappings of existing keys not working and some other keys I hadn't thought I was modifying getting changed, eventually I realized that scan codes from showkey -s were the common factor in the problem cases.

Instead, if you must use showkey, use regular showkey output (without -s) to find the current mapped keycode for the key, and work backwards through the table from getkeycodes to figure out the key's scan code. If there are multiple scan codes mapped to the same keycode, it may take a little mastermind and/or trial and error to work out the right scan code for the key.

Or, rely on other sources of scan code information such as atkbd log messages in dmesg output (use dmesg -w to follow dmesg output), or the scan codes reported by evtest if your system is using the event device framework.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.