1

My goal is to set up a terminal in which a command-line interface program would behave as expected for the keyboard inputs (the program is written in xharbour originally for Windows but now I would like to port it to linux). I have chosen xterm to start with as it is simpler, no need for disabling default terminal key combinations.

With putty most of the characters work out well and for those that don't I use autohotkey, an ahk script and that does the job. For example, for Ctrl+F1: ^F1::SendInput ^[O5P

I tried and modified, recompiled the terminfo, changed it and changed the keyboard types but could not achieve to get a ^[O5P response for pressing Ctrl+F1 in terminal. If you know any way of doing this change, please tell me... I have read trough hundreds of pages that supposedly do this but all those changes did not made any effect or not the expected effect.

So I left trying to modify the terminal settings to achieve my Ctrl+F1 to ^[O5P goal and tried some commands and programs that would do something similar to autohotkey:

  • xmodmap, but for key combinations it's not working
  • xdotool windowactivate xyz type ^[O5P, this returns the char codes of individual characters
  • xmacro, it doesn't send keystrokes to other window
  • ironahk, I get an error right at the start with trying to run the example.ahk and couldn't find the commands that I wished for in its light manual.
  • bind '\e[1;5P":"\e[O5P"', here the first keycode is what I currently get when typing ctrl+f1 and after the one that I wish to get by this combination. No effect.
  • xbindkeys + xvkbd, didn't helped either.

Please help me if you already know, managed somehow to achieve this (change the key code returned for a key combination).

I use the latest CentOS and Ubuntu for testing.

obeliksz
  • 468
  • 9
  • 24
  • I didn't understand what you're doing, but if you want to change the escape sequence generated by xterm for a key you need to modify its translation table. I found a nice example at http://www.in-ulm.de/~mascheck/X11/xterm/XTerm – Alan Curry Aug 07 '12 at 07:13
  • The translation table in your link looks interesting... I have to find out where this is in Centos... Probably I told it in the complicated way what I'm doing but you got it what I would like to do: change the escape sequence generated by xterm for a KEY COMBINATION. – obeliksz Aug 07 '12 at 07:50
  • The example file I linked to is an X resource file. These are typically placed in `/etc/X11/app-defaults/` for a system-wide configuration, or `$HOME/.Xresources` or `$HOME/.Xdefaults` for individual user configuration. If you put it in the right location (whichever it might be for Centos), the file will be loaded at the start of your X session, and you can reload it in the middle of a session with `xrdb -merge filename` – Alan Curry Aug 07 '12 at 07:53
  • And one other option: you can add the translations to one specific xterm instance by giving the translation table resource as a `-xrm` option. Using a small piece from the example file to demonstrate: `xterm -xrm 'XTerm.VT100.translations: #override CtrlLeft: string(0x1b) string("b") \n CtrlRight: string(0x1b) string("f")'` – Alan Curry Aug 07 '12 at 08:05
  • Why not use the character sequence xterm actually generates and interpret that in your program as Ctrl+F1? Is that a limitation of xHarbour's terminal library? – echristopherson Aug 08 '12 at 01:15
  • It is easier this way, otherwise the generated xterm sequence can vary by distros and I would rather keep the code with minimal changes and have a little system/enviroment setup. – obeliksz Aug 09 '12 at 08:30

2 Answers2

3

xterm can be configured to send custom strings when certain keys are pressed by modifying its translation table. The translation table is part of the X resource database managed by the xrdb command.

There's a good example of a customized translation table for xterm here. It can be copied into your $HOME/.Xdefaults or $HOME/.Xresources and it will be loaded the next time you log in. To load it into your current session immediately, xrdb -merge $HOME/.Xresources. This won't affect any xterms that are already running. (You might be able to change the translation table of a running xterm with editres, but that's more trouble than it's worth.)

To provide a custom translation table for a single instance of xterm, use the -xrm option, as in

xterm -xrm 'XTerm.VT100.translations: #override Ctrl<Key>Left: string(0x1b) string("b") \n Ctrl<Key>Right: string(0x1b) string("f")'
Alan Curry
  • 14,255
  • 3
  • 32
  • 33
  • And any idea how to configure this for Putty? – obeliksz Aug 13 '12 at 11:42
  • Better make that a separate question. I'm not optimistic about the answer. xterm owes its flexibility to the Xt toolkit, which provides the sophisticated keybinding language. (xterm just provides the action functions, in this case "string"). No other graphics toolkit is so configurable. Xt: a great improvement over its successors – Alan Curry Aug 13 '12 at 23:43
  • http://stackoverflow.com/questions/11966534/ctrl-with-function-keys-in-putty here is the separate question :) – obeliksz Aug 15 '12 at 09:50
-1

Not directly answering the question, but ESC O 5 P is a quite-wrong thing for a terminal to be sending.

In brief: ESC O, otherwise called SS3 short for Single Shift 3, is a sequence that modifies the next character sent, putting it in the G3 graphical area instead of the standard one. This would modify the 5 and send the P directly. This isn't and has never been a good idea.

The correct thing to send for Ctrl-F1 would be CSI 1;5 P, a form of CSI P (being the F1 key) with the second parameter set to 5 (being the modifier bitmask).

LeoNerd
  • 8,344
  • 1
  • 29
  • 36
  • Thanks but I'm not a terminal pro and my concern is to make the terminal so that an xharbour program would understand my key combinations and with 1;5P it does not. – obeliksz Aug 14 '12 at 07:24