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 workingxdotool
windowactivate xyz type ^[O5P, this returns the char codes of individual charactersxmacro
, it doesn't send keystrokes to other windowironahk
, 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.
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")'
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).
来源:https://stackoverflow.com/questions/11840763/change-the-escape-sequence-generated-by-xterm-for-key-combinations