?
Solved

Accessing function key in Visual C++ SDI

Posted on 2000-04-28
9
Medium Priority
?
340 Views
Last Modified: 2012-05-04
A Visual C++ SDI application running under Windows NT 4.0 needs to get control when a user presses one of the function keys on the keyboards, such as: F1, F2, F3.

How can this be done?
0
Comment
Question by:joex
[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
  • 4
9 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 400 total points
ID: 2760580
The window with the focus will get a WM_KEYDOWN/WM_KEYUP message pair when the key is pressed.  You can simply handle the messages in the window's window procedure.  

Dependig on what you are doing, you can also define a keyboard accelerator to convert the key to a command, in which case a WM_COMMAND message will be sent to the window with the focus.

Let me know if you have any questions.   More details from you might also help.
0
 

Author Comment

by:joex
ID: 2760724
After registering for the WM_KEYDOWN event, the event handler does not get control when one of the keyboard entries, such as the function key is pressed.
 
Is it possible for one application to field keyboard inputs, even if another application has the focus?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2760823
>> the event handler does not get control
Does the window that is to be handling the key have the focus?  what sort of window is this?

>> Is it possible for one application to field
>> keyboard inputs, even if another
>> application has the focus?
It is possible, but a lot of work.  You wouldn't want to do this if yuou could avoid it.   Is that the case you have?
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.

 

Author Comment

by:joex
ID: 2761003
>>>> the event handler does not get control
                   
>>Does the window that is to be handling the key have the focus?  what sort of window is this?

I tried in both a SDI application and a dialog-based application.  


>>>> Is it possible for one application to field
>>>> keyboard inputs, even if another
>>>> application has the focus?

>>It is possible, but a lot of work.  You wouldn't want to do this if yuou could avoid it.   Is that the
                    case you have?

Possibly.  The users don't even want to have to pop-up a dialog.  They just want to hit function keys.  
0
 
LVL 22

Expert Comment

by:nietod
ID: 2761126
>> I tried in both a SDI application and a dialog-based application.  
My point is that a windows appliction usually has many windows open at a time (remember that even though a user may consier only the big movable window a window many other things are windows too, a button, edit box, static text box etc are all windows.)  So you probalby have many windows in your app (either SDI or dialog).  Only the window with the focus will get the keyboard message.  This is usually desirable.  Usually you just control the focus so that the messages are sent to the window you want.  so the question is, what window has the focus, have you done anything to insure that, or at least why does that window have the focus? Can the focus change?  what window should be handling these messages.  whould it handle them always, or only when it has the focus?

the most common behavior is that the a window responds to a certain key only when it has the focus and not when it doesn't.  However, if you have a case where an action should be performed no matter what window has the focus, it is likely that you want to use a keyboard accelerator to run a command.  That is also failrly  common.

>> The users don't even want to have to
>> pop-up a dialog.  They just want to hit
>> function keys.
What do you mean?  What is supposed to be mappening?  

I need to understand your situation much better.
0
 

Author Comment

by:joex
ID: 2764457
It is not possible to control the focus via some modal dialog or something like that.  Users are going from a touch panel based design to one where the control comes from a GUI.  However, they do not want to pop up dialogs to change  camera presets.  They just want them to be available from function keys.  It is possible that they do not want to have the focus to be placed in the GUI window in order to change presets, but this is a tbd.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2764466
I still don't understand the situation well enoguh.  But woudl ti be reasonable to say that the function keys should be available at all times when any window of your application has the focus, not just a particular window.  If so and if there are a limited number of function keys you need to handle  (less than say 20) you probably should just define commands for these function keys and keyboard accelerators to convert the function keys to commands.  
0
 

Author Comment

by:joex
ID: 2764875
I would like to know how you define commands for these function keys and keyboard accelerators to convert the function keys to commands
0
 
LVL 22

Expert Comment

by:nietod
ID: 2765547
A command is simply a number that is sent as a parameter with the WM_COMMAND message.   you define commands by creating unique numbers or IDs for the commands you need to support.  Typically this is done by creating constants that have unique numbers, like

const int OpenCommand = 1001;
const int CloseCommand = 1002;
const int SaveCommand = 1003;

If you have menus in your program, you probaly are already creating commands.  VC may have some sort of wizzard or other feature that allows you to create commands in a fancy, more automated ways, I don't know.  

An acceletorator links a function key to a command.  To create an accerator you can create an acceletor entry in the program's resource source file.  You can look up "ACCELERATORS Resource" in the VC help for a description of how to do this along with samples.  VC does have an automated way to create accelerator resources.  Go to the "insert" menu and then sellect "resources...".  From the list in the dialog choose "accelerator".

For an overview of accelerators and commans go to the help in the table of contents at

Platform SDK
   User Interface Services
       User Input
          Keyboard Accelerators

and then read forward (down?) from there.  There are about 20 "pages" there on it.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

719 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