Solved

Input From Function Keys

Posted on 2000-02-28
11
414 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
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

749 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