[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Using function keys in C or C++

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
tsar
Asked:
tsar
1 Solution
 
isaacguyCommented:
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
 
fasterCommented:
This depends largely on the platform and whether you want your key functions to be active when other applications are running.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now