Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Input From Function Keys

Posted on 2000-02-28
11
Medium Priority
?
428 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 200 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

618 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