Solved

Input From Function Keys

Posted on 2000-02-28
11
415 Views
Last Modified: 2012-08-14
How do I accept inputs from function keys in C++ (I'm using Borland v 4.52)?
0
Comment
Question by:kiphughes
[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
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 2564730
The F keys cause WM_KEYDOWN messages to be sent to your app just like any other key.  The virtual key codes for them are:

VK_Fn    where n is the number of the key.  So VK_F1 is the F1 key.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2564842
What sort of application is this?  is it ia windows GUI application or a console application?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2564845
What sort of application is this?  is it ia windows GUI application or a console application?
0
Industry Leaders: 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!

 
LVL 22

Expert Comment

by:nietod
ID: 2564877
What sort of application is this?  is it ia windows GUI application or a console application?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2564878
Sorry for the multiple posts.  EE was apparently accepting post but not "returning" the page.
0
 
LVL 1

Author Comment

by:kiphughes
ID: 2565730
nietod, it's a console application.

jhance, thanks for the input, but it doesn't help much. is there a header file that i need to include first? what is the syntax for the function? i've looked up the key words u gave in my help file, but no luck.

thanks.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2565873
For a console applicationt that is useless--that is why I asked.

How are you getting the input?

  If you are using standard C/C++ input functions, then when a function key is pressed you will get a NUl (0) charcter followed by a 2nd character that indicates which key was pressed.  Like 0x3B for an F1, 0x3C for F2, 0x3D for F3 etc.

0
 
LVL 32

Expert Comment

by:jhance
ID: 2565885
Maybe a bit of background information information on your application would be helpful.

VK_F1 is defined in winuser.h from the Windows SDK.  I'm sure that even Borland C has this include as it's fundamental.  Usually you don't include it directly but rather it's brought in by windows.h.

For a Windows GUI application you need to handle the WM_KEYDOWN message.

For a console app, the F keys return 2 chars each according to the following table:

F1  0x00 0x3b
F2  0x00 0x3c
F3  0x00 0x3d
F4  etc.
F11 0xe0 0x85
F12 0xe0 0x86

0
 
LVL 1

Author Comment

by:kiphughes
ID: 2569822
jhance,

i've got windows.h, but not winuser.h

can u provide me with a sample program that will loop until a key is depress and determine what key it is?

thanks.
0
 

Accepted Solution

by:
mpersano earned 50 total points
ID: 2619915
As already pointed out, on a console application you can use the standard C/C++ input functions to read the keyboard. When a function key is pressed, you first receive a 0, followed by the key code:

F1  0x3b
F2  0x3c
....
F10 0x44
F11 0x85
F12 0x86

You asked for some code to show the name of the function key that was pressed - here is it. Hit ESC to quit.

#include <stdio.h>
#include <conio.h>

main() {
    unsigned char c;

    while(1) {
        if((c = getch()) == 0x1b) break;
        if(!c) {
            c = getch();
            if((c >= 0x3b) && (c <= 0x44)) printf("F%d ", c - 0x3a);
            if((c == 0x85) || (c == 0x86)) printf("F1%d ", c - 0x84);
        }
    }
}
0
 
LVL 1

Author Comment

by:kiphughes
ID: 2620280
thanks. how is this done for GUI?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

734 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