Re: How to recognize the Function keys in C



>> I want to be able to use all 12 Function keys in my program.
>> Can someone help me maybe on this one?
>>
>> I guess that those function keys also have an ascii number.
>> But so far I haven't seen none of the funtion keys in my ascii chart.
>
><Offtopic>
>
>Depending on the terminal type, function keys usually generate a specific
>sequence of characters, often starting with ESC (0x1b). For example, on my
>terminal, the F1 key generates the string "\x1b\x5b\x31\x31\x7e"
>
>Reading function keys is something very system- and OS-specific and is not
>possible with only ANSI-C; you might want to ask this question in the
>appropriate newsgroup that discusses programming on unix/linux. You also
>might want to look into the 'curses' and/or 'termcap' libraries, which are
>specially designed to handle keyboard and screen IO on unix systems.

It is possible to read the characters generated by a function key
in a system-independent manner. To figure out what sequence of
characters go with what keys, you can ask the user to "Press the
F1 key followed by the key used to end a line of input (typically
Enter or Return)", then fgets() (possibly multiple times if your
initial buffer wasn't long enough) the result and save it. This
will screw up if the function keys generate something interpreted
as a newline. Repeat for other function keys that you will use.

Distinguishing the function key from an individually-typed sequence
that matches it isn't practical (most programs that do this depend
on character-at-a-time I/O and timing). On many systems, this
reduces to "don't try to use the ESCAPE key as something the user
will type by itself".

C also doesn't have non-blocking or character-at-a-time I/O, so the
user has to press ENTER (or whatever) to finish a line of input
before it's visible to the program. This severely messes up any
idea you might have about the user pressing F1 and having a help
screen appear immediately.

The "termcap" database doesn't do anything that can't be done in
ANSI C, although the data contained in it is terminal-specific.
ANSI C allows getenv("TERM") which can be used as a key into the
database to look up the sequences generated by various function
keys on the terminal (or emulation thereof) that the user is using.

Gordon L. Burditt
.



Relevant Pages

  • Re: Function keys changed
    ... In Delphi, F1 and F3 act as described, the rest of the F keys don't do anything. ... The master browser has received a server announcement from the computer FLOGGER that believes that it is the master browser for the domain on transport NetBT_Tcpip_{2E72BA47-98C5-4BA6-9. ... the error message you quote has absolutely nothing to do with whether your function keys work correctly. ... On any Microsoft network running Netbios over TCP/IP the Browser service acts as a "telephone directory" keeping a list of all the machines on the network by Name and IP address. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Sending function keys to MSDOS application
    ... I am using a Delphi unit by Steve Seymour: ... It seems to work fine when you send keys to the Windows calculator. ... But when I used it to send keys to an MSDOS program ... I can manually press the function keys and they work normally. ...
    (comp.lang.pascal.delphi.misc)
  • Re: F lock key!
    ... > | remapping of the function keys. ... > |> If I were to design the keyboard I would have made the ... > | function keys as intended I have to MANUALLY switch the ... > | when I switch to those applications. ...
    (microsoft.public.windowsxp.hardware)
  • Re: F lock key!
    ... |> keyboard has power and then pressing the F2 key or if I ... | remapping of the function keys. ... | function keys as intended I have to MANUALLY switch the ... | when I switch to those applications. ...
    (microsoft.public.windowsxp.hardware)
  • using terminal to ssh into a screen session
    ... SSH and the TERM interpretations I think. ... Typically I SSH into my home server, then open a screen session ... Trouble is with the backspaceand function keys ...
    (comp.sys.mac.system)