Solved

Using function keys in C or C++

Posted on 1998-04-13
2
274 Views
Last Modified: 2010-05-18
Hello, how does one uses function keys in C or C++?For instance, I would like to link several functions into one programs. Then, by assigning various functions keys would like to call the necessary  function. A good example would be: Press f1 to go to help, f2--, f3--.
I'd be grateful for an answer,
Victor
0
Comment
Question by:tsar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
isaacguy earned 200 total points
ID: 1258121
Here's some code:

#include <conio.h>

#define KEY_F1 315
#define KEY_F2 316
#define KEY_F3 317
#define KEY_F4 318
#define KEY_F5 319
#define KEY_F6 320
#define KEY_F7 321
#define KEY_F8 322
#define KEY_F9 323
#define KEY_F10 324
#define KEY_F11 389
#define KEY_F12 390

int GetAKey(void)
{
     int ch;
     ch = getch();
     if (ch)
     {
          return ch;
     }
     else
     {
          return getch() + 256;
     };
};

This function will return the extended or standard key value for each key pressed.
The F keys values are above the code.  To find the values for other keys, simply make a test prog that outputs the values of a key when you press the key and add them to the define section.

To test for an F key:
int key;
key = GetAKey();
if (key == KEY_F1)
{
     //etc.
};

Good Luck!
0
 
LVL 7

Expert Comment

by:faster
ID: 1258122
This depends largely on the platform and whether you want your key functions to be active when other applications are running.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question