Solved

Input From Function Keys

Posted on 2000-02-28
11
406 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

746 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

10 Experts available now in Live!

Get 1:1 Help Now