473,729 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to recognize the Function keys in C

Hello,

I'm trying to write a console based program in C in Linux.
I want to use the function keys in my program, but I don;t know how to
let the C program know when for exmaple the F1 key is pressed.

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.

Cheers,

Broeisi
Dec 31 '05 #1
4 6702
Broeisi <br*******@gmai l.com> wrote:
I'm trying to write a console based program in C in Linux.
I want to use the function keys in my program, but I don;t know how to
let the C program know when for exmaple the F1 key is pressed.

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\x 31\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.

--
:wq
^X^Cy^K^X^C^C^C ^C
Dec 31 '05 #2
On Sat, 31 Dec 2005 10:26:38 -0600, Broeisi wrote:
Hello,

I'm trying to write a console based program in C in Linux.
I want to use the function keys in my program, but I don;t know how to
let the C program know when for exmaple the F1 key is pressed.

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.


Study the source for something like vim, which is a mature,
portable codebase that uses the keyboard extensively.

--
"The secret of being boring is to say everything." - Voltaire
Dec 31 '05 #3
>> 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\x 31\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
Dec 31 '05 #4
Broeisi wrote
(in article <4f************ ********@casema .nl>):
Hello,

I'm trying to write a console based program in C in Linux.


Google for curses and/or ncurses, possibly with the addition of
"example code". It's off-topic here, because standard C doesn't
know what a function key is. Many C implementations are
available for platforms with no keyboard at all.

Even worse, you'll discover that not all terminal types even use
the same mapping for keys, so you even that is not standard, but
that is one of the thing that curses can help with (provided you
have correct terminal type descriptions for the associated
hardware).
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 31 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1560
by: Michael G. Schneider | last post by:
On Nov 16th I asked about a problem where ASP pages, which were located on a UNC-share, would not work correctly. IIS would not recognize, if the ASP page has been changed. Nobofy had a hint here, so I later asked the same question on microsoft.public.inetserver.iis. There I learned to know, that this is indeed a known feature of IIS6. Certain registry keys have to be set, in order for Change Notification to work. It is described in... ...
1
5420
by: Don W. | last post by:
I need to use some function keys as speed-keys (instead of clicking a button with the mouse.) Using this code doesn't display any codes for the function keys: <html><body> <SCRIPT LANGUAGE="JavaScript"> document.onkeypress = Check_key; function Check_key() {
0
1000
by: OC | last post by:
I am attempting to trap special keys on the keypad for a high-speed dataentry application. It MOSTLY works, however it does not work on every computer. IOW, Keys.Divide, Keys.Multiply, and Keys.Subtract do not always fire on some machines and I don't see an OEM equivilent for these. I am using the following format: private bool HandleKeys(Keys keyCode) { bool ret = false;
1
6840
by: Steve | last post by:
I would like to override the IsInputKey function in order to trap the arrow up/down keys in the Key Events. I understand that arrow keys don't have a char representation and thus, hard to trap. Someone wrote this override for IsInputKey in C# which apparently worked, and I tried to convert it to VB.Net but not working. Here is the C# version and following - my conversion. It would be great if anyone out there knows how to do this...
1
2050
by: Sam Samson | last post by:
Greeetings All .. For my users convenience I have mapped function keys F2 .. F12 to change the tabs on the Tabcontrol. Works like a charm <ominous musicuntil one hits F8</ominous music> That particular tabpage has a webbrowser object embedded in it .. and after it flicks to that tabpage it no longer plays nice with the other Tabpages .. click on another Tab using the mouse and all is wonderful again. (unless
5
2105
by: CyberSoftHari | last post by:
How to Recognize key pressed when the application is in system tray? I am using a context menu with some hot keys (like Alt+Ctrl+Delete) once I press the key my appropriate command should trigger. Can any one Point me to Recognize key pressed when the application is in system tray Front end : C#.Net or C# 2005 Thank you
9
2396
by: Wingot | last post by:
Hey, I am using Visual Studio 2008 Beta 2 for some application development in C#, but I presume that the following question applies equally well to any environment.
5
1596
by: =?Utf-8?B?Sm9obiBLb3R1Ynk=?= | last post by:
Hi all, We lease a non-managed Web Server running AV software but no IDS. It is Windows 2003 STD which receives automatic nightly Windows Security patches at 3AM. When I logged into the RDP console on Monday I saw what looked like a Password Cracking software running with the name at the top of the window E-Security. It looks like it had gone through 69,914,496 permutations already. I went into Task Manager and killed a program I did...
0
8763
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9202
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4528
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.