Solved

Using function keys in C or C++

Posted on 1998-04-13
2
262 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
Comment Utility
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
Comment Utility
This depends largely on the platform and whether you want your key functions to be active when other applications are running.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now