Solved

Input From Function Keys

Posted on 2000-02-28
11
413 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
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.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

840 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