If you want to "send" a function key use the appropriate syntax
^F1::SendInput {F5}
That would cause Putty to act as if you had pressed F5 and it will then send an appropriate sequence of characters (an Escape Sequence) to the server.
PC Server
+---------------------+ Network +-------------------------+
| [AHK] ----> [Putty] | ============> | [TTY] ------> [Program] |
| F5 | Esc [ 15 ~ | Esc… | ^ |
+---------------------+ | | | F5 |
| v | |
| $TERM------[Curses] |
| | |
| /usr/share/terminfo |
+-------------------------+
At the server, the Escape sequence is first processed by the TTY handler (looking for Interrupt signals etc) and then given to your server program which typuically hands it to the curses
library which translates Escape sequences back into names of Functions. The program then decides what to do as a result of receiving that.
The actual Escape Sequence depends on the "terminal emulation". By default, Putty emulates an xterm. The Curses library uses the value of environment variable TERM to look up in terminfo what function is represented by an escape sequence.
Escape sequences for function keys can be found in /etc/termcap, here's a few
SCO PuTTY PuTTY
Key Termcap VT100 VT220 ANSI XTERM VT400
--- ------- ------- ------- ------ ------ -------
F1 k1 Esc[OP Esc[OP Esc[M Esc[OP Esc[11~
F2 k2 Esc[OQ Esc[OQ Esc[N Esc[OQ Esc[12~
F3 k3 Esc[OR Esc[OR Esc[O Esc[OR Esc[13~
F4 k4 Esc[OS Esc[OS Esc[P Esc[OS Esc[14~
F5 k5 - - Esc[Q Esc[15~ Esc[15~
F6 k6 - Esc[17~ Esc[R Esc[17~ Esc[17~
F7 k7 - Esc[18~ Esc[S Esc[18~ Esc[18~
...
F10 k0 - Esc[21~ Esc[V Esc[21~ Esc[21~
F11 k1 - Esc[23~ Esc[X Esc[23~ Esc[23~
...
F14 kD - Esc[26~ Esc[Z Esc[26~ Esc[26~
F15 kE - Esc[27~ Esc[a Esc[27~ Esc[27~
...
F36 FP -
...
F63 Fr -
Notes
- The VT100 series had only four function keys labelled PF1 to PF4
- The VT220 had 20 function keys labelled up to F20
- The VT220 used a function key at position 5 for a "break" function. (hence gap above)
- Not all emulators or extant termcap/terminfo files agree about the above.
- There are strange gaps in the progression.
- xterm is not a definition, it's an unruly family of misfits, no two alike.
- Ditto "ANSI"
- Many emulators use something like Shift+F1 for F13, Alt+F1 for F25 etc.
- In PuTTY, shift+F1 is the same as F11 (not F13)
- Yes it's a mess. That's why we let PuTTY and Terminfo hide it from us.
I knew the pure {specialKey} syntax only that I need key combinations. For ex.: +F1::SendInput,^6s{F1} and ^F1::SendInput,^6c{F1} – obeliksz – 2012-10-24T13:04:44.537
What I dont get is how this escape code is composed/works: it decreases as I increase a number in code (see example in the question). Is it possible to do an addition/substraction for a {key}? For example: {Enter-3} I get the code 13 from my test program, I want to send a signal that returnes 10. – obeliksz – 2012-10-24T13:21:50.373
According to your figure I would think that changing the xterm terminfo should change the terminal's reactions to the changed escape code? I tried this (modified terminfo and recomplied with tic) but it didn't applied my modification at least it was of no effect. Was I just mistaking the terminfo file? I think I changed more xterm terminfo files if not all as TERM returned xterm. – obeliksz – 2012-10-24T13:26:23.683
@obelisk: A) terminals don't react to codes sent to the server (only those sent from the server). B) Why are you trying to use AHK to send Escape sequences to PuTTY? Send Function Key presses to Putty, let Putty decide what Escape sequence to send. C) There is only one "xterm" file in the Terminfo library (exact spelling). – RedGrittyBrick – 2012-10-24T14:56:19.370
I'm using AHK because otherwise I cant make putty to react to my key combinations. I accepted your answer because you explained the how it works well but it doesn't work for me... I modified the xterm from usr/share/teminfo/x/xterm... modified kf1 from /EOP to /EOX and tic recomplied it but I don't see the effect... I tested with xterm, TERM returned xterm. For cat F1 I got before EOP and still I get just EOP. This is one part, the other would be to get the escape code I want, how these letters/numbering adds up – obeliksz – 2012-10-25T05:26:51.197