Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Super/Windows/mod4 key bindings for eclipse

I'd like to setup some key bindings in eclipse (3.7.2) involving the key ("windows" key), but it doesn't seem to be picking up that modifier key when I press it. Why? What can I do so it detects it?

like image 852
srparish Avatar asked Jul 10 '12 20:07

srparish


2 Answers

You have "linux" tagged in your question, so I'll assume you're using Linux and X ...

So, to use Super with Eclipse, first you have to discover whether you have a Super, and if not, make one. The rest of this is probably way more than you need on the subject of xmodmap.

The first thing to do is see if you already have a Super modifier key. Run "xmodmap -pm" to see what your modifiers currently are. Here's a common output:

$ xmodmap -pm
xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

In the output above, a bunch of keys are already mapped to Super, with (hex) keycodes 0x85, 0x86, 0xce, and 0xcf. To see if anything on your keyboard happens to be one of those keys (which isn't always the case), run "xev" in a terminal and move your mouse pointer into "xev"'s mostly-white input window, and try different keys. Typical output looks like this for keys (try control and shift to see examples) - pay particular attention to the third line with the keycode and keysym name, here 64 and Meta_L.

Be sure to try your "Windows" key too, to see what keycode and mapping it has currently.

KeyPress event, serial 42, synthetic NO, window 0xe600003,
    root 0x6b6, subw 0x0, time 2232472454, (-1,167), root:(871,683),
    state 0x0, keycode 64 (keysym 0xffe7, Meta_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

Find the "keycode" part and covert it to base 16. If you've hit one of the Supers, your converted code will match one of the (in the example above, four) hex keycodes, and show Super_L or Super_R instead of the Meta_L shown above.

If you don't have any keys mapped to Super, or it turns out that none of them exist on your keyboard, then use xev to find the keycode for the key you want to use for Super (CapsLock might be a good choice for some folks), then use xmodmap or some other tool in your desktop's UI to set it up. The latter is outside of the scope of this reply, but with xmodmap, you could just make a file named .Xmodmap in your home directory with this in it:

! note: replace the 0xff below with your *actual* Super_L key's keycode.
! note: whether to use mod3 or mod4 depends on your environment.
keycode 0xff = Super_L
clear mod4
add mod4 = Super_L

Apply the results with "xmodmap ~/.Xmodmap". Many X startups will automatically apply these for you. If you're using Ubuntu Unity, look up Startup Applications in the Dash and add one for that same command. I'm not sure if "~" works in the context, you might want to try $HOME or just use your home directory there. It ends up producing a file in ~/.config/autostart/xmodmap.desktop like this one (erlkonig = me; put your home in instead):

$ cat ./.config/autostart/xmodmap.desktop
[Desktop Entry]
Type=Application
Exec=/usr/bin/xmodmap /home/erlkonig/.Xmodmap
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=Xmodmap Keymap Settings
Name=Xmodmap Keymap Settings
Comment[en_US]=Set Keyboard Bindings
Comment=Set Keyboard Bindings

You can verify the results with "xmodmap -pm" or "xev". Here's the output for the former for my environment from a more complex setup (which probably won't match what you'd want yourself).

$ xmodmap -pm
xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x7f)
control     Control_L (0x25)
mod1        Meta_L (0x40),  Meta_L (0xcd)
mod2        Alt_L (0x6c),  Alt_L (0xcc)
mod3        Super_R (0x69),  Super_L (0x85),  Super_R (0x86),  Super_L (0xce)
mod4        Hyper_L (0x42),  Hyper_L (0xcf)
mod5        Num_Lock (0x4d)

Hyper replaces CapsLock (which I've moved elsewhere); I use it for window manager functions, like Hyper-f to "front" a window, Hyper-r to resize, etc.

For another random(ish) example of what you can with xmodmap, here's a keymap that map whatever keycode 78 is to Mode_switch, and then allow you to combine it with ', ", `, and ~ to enter prefixes that make your next vowel have the similar diacritic on them. You can also use the Mode_switch with a to get æ, d to get ð, ? to get ¿, and some others.

! note: 78 is probably not the keycode most would want here; pick your own :-)
keycode 78 = Mode_switch
!                      no mods shift           mode-switch shift+mode-switch
keysym a          =          a A                        ae AE 
keysym d          =          d D                     thorn THORN
keysym n          =          n N                    ntilde Ntilde
keysym o          =          o O                    oslash Oslash
keysym t          =          t T                       eth ETH
keysym s          =          s S                    ssharp
keysym 0          =          0 parenright           degree     
keysym 6          =          6 asciicircum dead_circumflex
keysym 8          =          8 asterisk           multiply    
keysym apostrophe = apostrophe quotedbl         dead_acute dead_diaeresis
keysym grave      =      grave asciitilde       dead_grave
keysym comma      =      comma less           dead_cedilla guillemotleft
keysym period     =     period greater            NoSymbol guillemotright
keysym slash      =      slash question           NoSymbol questiondown
keysym 1          =          1 exclam             NoSymbol exclamdown
keysym equal      =      equal plus               notequal plusminus

for more information use "man xmodmap".

like image 57
Alex North-Keys Avatar answered Oct 05 '22 05:10

Alex North-Keys


Eclipse does not hook the Windows key. The only thing you can do is use a tool to rebind the windows key to, for example, CTRL+ALT+SHIFT (if you don't use that). Tools like AutoHotkey may do the job.

Then, whenever you press the windows key, it will be as if you pressed CTRL+ALT+SHIFT, which you can then use to bind your desired hotkeys.

like image 42
Timo Türschmann Avatar answered Oct 05 '22 06:10

Timo Türschmann