Question

While Ctrl+Left/Right are usually mapped to moving the cursor one word to the left/right, Ctrl+Up/Down aren't usually mapped to anything in Linux apps. In the same spirit, I want to remap Ctrl+Up/Down to 5 repetitions of the Up/Down keys. Is there any way to do it with xmodmap or through the XKB configs? I've done some really custom stuff with XKB (my right Alt is Overlay2) but I have no idea where to start to be able to send multiple events / multiple keys for one event / key.

As a workaround, I can do this in vim:

(n/i/v)map <C-Up> <Up><Up><Up><Up><Up>
(n/i/v)map <C-Down> <Down><Down><Down><Down><Down>

However, getting this to also work in gedit and eclipse would be a good enough workaround for me. Any ideas?

Was it helpful?

Solution

You can use xbindkeys for this. You would need to write an .xbindkeysrc and start xbindkeys with your X Session (You could use either .xinitrc, .xsession or your the appropriate option in your DM/WM if it has one). The you will need something to send keys to X Programs. I used xte from the xautomation package but you can also use something like xmacro (example here).

In your .xbindkeysrc you write something like this:

"xte 'keyup Control_L' 'keyup Control_R' 'key Up' 'key Up' 'key Up' 'key Up' 'key Up'"
     Control + Up

same thing for Control + Down (the linebreak in the example is needed). This will release the control keys (important if you don't want to end up with infinite up) and then press up 5 times.

OTHER TIPS

Based on Trudberts's answer, I ended up with having .xbindkeysrc as follows:

"xte 'keyup Control_L' 'keyup Control_R' 'key Up' 'key Up' 'key Up' 'key Up' 'key Up' 'key Up' 'keydown Control_L'"
    Control + Up
"xte 'keyup Control_L' 'keyup Control_R' 'key Down' 'key Down' 'key Down' 'key Down' 'key Down' 'key Down' 'keydown Control_L'"
    Control + Down

This fixes two things. First, if holding control down, every press of Up/Down makes it go move five (rather than four) lines and it also works after the first press (Trudbert's answer didn't).

There are two problems. The Control_R doesn't work well, and holding Ctrl+Up pressed won't auto repeat the key, similar to how holding just Up pressed works. I'll award Trudbert the bounty, but at the end of the period.

In the meantime, hopefully someone will come with an idea of how to fix this. I was thinking of a custom script, that keeps repeating 5 Up's until there is a release event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top