Sublime Forum

Mapping special keyboard keys

#1

I have a number of special keys on my keyboard (Microsoft Natural Keyboard) that I would like to utilize. Some of these are identified by xev on linux as XF86Forward, XF86Back, XF86Launch5, XF86Search etc.

However, SublimeText seems to ignore these. I can enter sublime.log_input(True) in the console and see, for instance, “f1” when I press f1, but nothing for these keys. I know that they are active because I can seen them pressed from xev.

0 Likes

#2

After some more digging, I believe my window manager is slurping those keys and they’re never making it to the application…

0 Likes

#3

I would definitely suggest seeing if the window manager is configurable in this regard to ignore those keys if it recognizes them, since that’s generally the reason why keys don’t appear in the Sublime input log.

That said, on my Linux machine only the Mail/Explorer/Calculator buttons are handled by the WM but the others are not (This keyboard doesn’t have a key for Web, but it’s similarly mapped by the WM). I presume that’s because the dedicated application buttons are more global than say back and forward, which is better used as an application specific key binding.

Generally speaking, if pressing the key while xev is running gets it to generate output, the WM is probably not catching it; xev won’t tell me the key code for XF86Mail unless I tell the WM to ignore it.

Something to try would be to add the following lines to ~/.Xmodmap (or create the file if it doesn’t already exist):

keycode 166 = F13 NoSymbol F13
keycode 167 = F14 NoSymbol F14

Once you do that, execute xmodmap ~/.Xmodmap in a terminal to make the bindings active right away.

Here the 166 and the 167 are the key codes from xev for the XF86Back and XF86Forward keys; the part after the = remaps those keys to be F13 and F14 respectively. If you use input logging in Sublime as you outlined above, you should see those keys being reported in the console when you press them, and they should then be bind-able as well.

You can extrapolate bindings for the other keys as needed, although you may need to tell the WM to keep it’s fingers off of the application keys if you want to use those for something. There may well be better substitute key mappings than these (and it may not be a good idea if your keyboard has a physical F13 key ;)) depending on what you’re trying to do.

3 Likes

#4

Thanks for the suggestion. I did notice last night that I could map XF86Forward to KP_0, but it did not occur to me to map to function keys that don’t exist on my keyboard :wink:

This should do the trick for me.

Keywords for future googlers: these are called multimedia keys.

-K

1 Like

#5

Anticipating a problem…

I remapped CapsLock to function as a left-mouse button a year ago and found that getting my ~/.Xmodmap file loaded automatically on boot-up was harder than it sounds. Here are the tech notes I wrote (a habit I have to avoid having to solve the same problem 5 years down the line):


Auto-Load ~/.Xmodmap On Boot:

The problem is that ~/.Xmodmap must be loaded very late in the start up sequence.

Note: Comments are not allowed in files read by xmodmap and cause failure if they are added.

Placing the line /usr/bin/xmodmap /home/username/.Xmodmap in ~/.profile, ~/.xinitrc, and ~/.xsessionrc all failed.

Creating the root file /etc/X11/Xsession.d/80_user_xmodmap to run the command, as suggested in How [sic] persistently remap keys in Ubuntu 16.04?, also did not work.

Reluctantly I used the graphical start up tool:

Linux Mint Menu --> Preferences --> Startup Applications
And manually added: /usr/bin/xmodmap /home/username/.Xmodmap

Despite the inelegance of the solution it works perfectly.

HTH.

0 Likes

#6

The Sublime Text Developers have been getting better at adding key support. They finally added F13 through F20 keys, but they forgot to add F21 through F24 keys ( I have Logitech G910 and use M1G6-M1G9 for F13-F16, M2G6-M2G9 for F17-F20, M3G6-M3G9 for F21-F24 - which is really helpful )…

Having these extra keys is amazing and very helpful.

When the keys were not supported, I used AutoHotkey and bound the keys to weird combinations such as CTRL ALT SHIFT END or something strange that isn’t in use by anything else…

Creating an AutoHotkey script is easy and it supports all keys as long as they have an identifier, and most do… I would also be surprised if someone hasn’t already made a script to support your keyboard - a lot of these keyboards with special keys, mice and so on have many scripts out there so it could be as easy as finding one, downloading it, and changing the key-presses. Some scripts may even have a GUI attached to make binding keys easier.

Then, simply bind the obscure CTRL ALT SHIFT END key in Sublime Text and you’re good to go until native support can be added.

0 Likes

#7

Build 3181
29 November 2018

F21…F24 keys can now be bound

1 Like