• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

How do you monitor keyboard input for a modal dialog box?

I wish to have a modal dialog without any visable buttons, and the only way to continue is to press the special key combination on the keyboard.

Is this possible?
If so, how would I do this?  
Do I use the OnKeyDown/OnKeyUp functions or what?

Thanks in advance.
0
TrainMan
Asked:
TrainMan
  • 4
  • 3
1 Solution
 
mikeblasCommented:
No.  The dialog manager eats all input messages and routes them to controls. You need to install a keyboard hook.

See the documentation for SetWindowsHookEx().

If you want a sample, just ask. But please tell me what specific key combination you want to use so I can make sure to show how to decode the virtual key codes.

..B ekiM
0
 
TrainManAuthor Commented:
If you're willing to provide a sample I'm not going to be stupid and say no.

The key combination is ALT F10.  I've already defined this as a virt key in my resource.

Thanks in advance.
0
 
mikeblasCommented:
No need for a translator resource.

Please see the TENHOOK.ZIP sample at http://www.nwlink.com/~mikeblas/samples/ . Please note that my samples (well, my whole webpage, actually) will someday move to http://www.mooseboy.com/ .

..B ekiM
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
TrainManAuthor Commented:
Thanks for the sample code.  I took a quick look at it, but I might have a couple questions later.  So if you don't mind, I'll respond through this thread.
0
 
TrainManAuthor Commented:
I have a SDI application without a Document.  The dialog I wish to use your code in is called AbortDlg.

Do I need to have your code global to the app, in which case it would be located in MainFrm.cpp I guess, or in the AbortDlg.cpp file?

I ask this because with it in my AbortDlg.cpp file, everytime the program gets to "if (nCode == HC_ACTION)" there is an Assertion Error!  :(

This could be operator error on my part too.  The SetWindowsHookEx code is in the CAbortDlg::OnInitDialog().

Please advise, thanks in advance.
0
 
mikeblasCommented:
An if statement can't possibly generate an assertion error.

 > have your code

Which part of "my code" are you referring to?

..B ekiM
0
 
TrainManAuthor Commented:
I realize fully that there is nothing wrong with your code, it is the way that I'm installing it that has a problem.  That's why the question.

I have a SDI application without a Document.  The dialog I wish to use your code in is called CAbortDlg.

Do I need to have your code global to the app, in which case it would be located in MainFrm.cpp I guess, or in the AbortDlg.cpp file?
0
 
gpbaldazziCommented:
I needed something like what I found in your TENHOOK.ZIP and I'm going to use it.
Just a question: is there any particolar reason for using your IsKeyDown() inside the MyKeyboardHook to retreive what key is being pressed? Could I parse wParam and lParam?
Thanks
Gian Paolo
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now