Getting X11 Keycodes

I wanted to use the key combination 'Fn+F2' to lock my computer with xscreensaver, but wasn't sure how to represent this key combination in the awesome wm rc.lua configuration file. Unfortunately you can't just insert combinations using 'Fn' like you would 'Ctrl', instead you must use the relevant 'Fn' combination keycode.

It turns out that you can use a tool called xev to print out events such as keypresses that occur in a X11 window. Running xev and pressing the desired key combination will output to a terminal information for this event, including the keycode. Doing this I discovered that 'Fn+F2' translated into keycode 160.

Adding the following to the key binding section of my rc.lua worked great.
awful.key({}, "#160", function () awful.util.spawn("xscreensaver-command -lock") end),
This was posted on Fri 31 Oct 2014 (4 years, 8 months ago) by Ryan McConville