Solved

Using function keys in C or C++

Posted on 1998-04-13
2
269 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

809 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