Solved

Using function keys in C or C++

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Test against App 49 137
Read file descriptor 3 in C 14 107
How to create frequencies of a variable from SAS dataset? 10 125
Constant string is of type char *   ? 7 30
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand recursion 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.

777 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