1

Is there any way of getting the arrow keys to act differently while the control key is pressed. On my system ^-Up and Up generate the same code...

5
  • I feel another AutoHotKey answer coming in!
    – Ivo Flipse
    Feb 18, 2010 at 20:56
  • You need to say more about what environment you're working in; also this is very similar to superuser.com/questions/110277
    – dubiousjim
    Feb 18, 2010 at 23:14
  • ...and your own closed question superuser.com/questions/110248! why not work with superuser.com/questions/94436 or another earlier question on this topic!?
    – dubiousjim
    Feb 18, 2010 at 23:20
  • Great,thanks; But can I do the same over SSH? It seems it doesn't use the same keymap.
    – Chris2048
    Feb 19, 2010 at 0:04
  • The duplicate of "How Can I get.." exist because one was migrated from SO, the other I created myself. That question in particular was maybe too complex because there where many layers to work with. I'm not sure "how-to-configure-putty..." is the same question. The environment is Linux.
    – Chris2048
    Feb 19, 2010 at 0:15

3 Answers 3

2

From my /etc/personal-linux-console.map:

# Up
control keycode 103 = F69

# Left
control keycode 105 = F71

...
string F69 = "\033<Cu>"
string F71 = "\033<Cl>"

From my /etc/rc.local:

 loadkeys -q /etc/personal-linux-console.map

I just chose these values arbitrarily. Now in the Linux console, Control-Up will send the five characters Escape-<-C-u->, and so on. You tell readline how you want to interpret that in your ~/.inputrc file.

With X, there are various places to tweak things. Some changes you can do with xmodmap. Depending on how you start X, you might be able to just save your xmodmap commands in ~/.Xmodmap or /etc/X11/Xmodmap and have them automatically loaded. Some changes will be too tricky for xmodmap, and you'll need to write XKB definition files (these reside under /usr/share/X11/xkb on my machine). These are very hairy and poorly documented. You should find what few docs and tutorials there are by Googling. In about a year we should see a new generation of XKB deployed, so I don't know how much sense it makes to invest time in learning the old format.

I don't know whether it's possible to do Control-keys with xmodmaps commands. I think it is. I used to have mine in custom XKB files (I needed the XKB files anyway, for some stuff.) Now I have the control keys configured in my X terminal (urxvt)'s config files. I use the same arbitrarily chosen sequence escape-<-C-u-> for control-up, and so on, so that I can use the settings in my .inputrc file (for readline) and for other terminal programs (mutt, elinks, and so on).

For some key redefinitions, it's also useful to write your own terminfo files so that terminfo-aware applications will be more likely to be able to handle/recognize them. I don't do that for my Control-arrow settings though. But for instance, if you have some key defined to output the string Escape-<-S-U->, you may want to use a terminfo file that declares that string as being the "Undo" key. Then in some applications you'll be able to just refer to that key as "Undo", no matter what it says on your physical keyboard.

It's complex. There's no general solution that's simpler. (Though if you were only concerned with a few keys, in a few applications, you may well be able to ignore some of the complexity.)

1
  • I used to remap keys using xmodmap, but of course that doesn't work when you are not using X. I'm guessing it is a little easier, though. +1 for general excellence in the service of excellent answers. Feb 19, 2010 at 9:09
0

Under the console, you can use dumpkeys to inspect the translation table and loadkeys to alter it (for instance, here to map them to additional function keys F13-F16):

box# dumpkeys
...
keycode 103 = Up
keycode 105 = Left
keycode 106 = Right
keycode 108 = Down
...

box# loadkeys <<EOF
control keycode 103 = F13
control keycode 105 = F14
control keycode 106 = F15
control keycode 108 = F16
EOF
2
  • Yes this works in *nix console, but then one needs to do something different in X, and something yet again different in Windows, and some terminal emulators will make this trivially easy others insanely difficult. Questioner has to elaborate, we shouldn't be guessing.
    – dubiousjim
    Feb 18, 2010 at 23:13
  • Elaborating: dumpkeys will tell you which keycodes are associated with which symbols. (See also showkey -k.) b0fh is assigning Control-up to F13, as I assigned it to F69. For F1-F20, I think you won't need to do the strings... bit I did in my answer; they'll already have strings associated with them. But you might want to use F1-F20 for other purposes (generally shift-F1 will generate F11 or F13). In that case, assign Control-up to a high Fkey and associate it with any string you want.
    – dubiousjim
    Feb 19, 2010 at 2:45
0

Put putty in xterm emulation mode if it can do that, instead of VT100. If it cannot do xterm emulation, switch to an emulator that can. VT100 cannot do the key sequences you want, period.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .