Click to See Complete Forum and Search --> : simulating hotkey
jaimelopez
October 22nd, 2001, 03:56 AM
Hi!
How can I detect that a key has been pressed (F5 f.e.) just in my application? I try the MCL Hotkey control from http://www.MerrionComputing.com but affectes the rest of the application (Other applications that use these keys donīt react anymore when my application runs minimized).
JHamilton
October 22nd, 2001, 04:31 AM
You have to enable KeyPreview on the form you wish to detect the keyup or keydown.
'for instance,
private Sub Form_Load()
Form1.KeyPreview = true
End Sub
Then, trap the event in your form's KeyUp/KeyDown:
private Sub Form_KeyUp(KeyCode as Integer, Shift as Integer)
If KeyCode = vbKeyF5 then
MsgBox "F5 has been pressed!"
End If
End Sub
Software is like sex, it's better when it's free - Linus Torvalds
Software is like sex, it's better when I get paid for it. - me
jaimelopez
October 22nd, 2001, 04:47 AM
Thanks!
It works fine, but my problem is that I have a MDI and a few amount of Child forms, and I cannot apply your hint for the Main Form, just for the child ones, which means more code to maintain. I was thinking more just placing some kind of control on the MDI form.
Jaime.
JHamilton
October 22nd, 2001, 05:24 AM
Is F5 tied to some sort of function in your app?
Software is like sex, it's better when it's free - Linus Torvalds
Software is like sex, it's better when I get paid for it. - me
Clearcode
October 22nd, 2001, 05:30 AM
You could call the MCL Hotkey's Unregister method when your application loses focus and call the Register method when it gains the focus...but that is a bit overkill as that control is intended for system-wide hotkeys.
Other than that you would need to subclass each of your forms (you only need one VB_WNDPROC) and whenever you get a WM_CHAR command check if it was F5 and if so process it, otherwise pass it on for default processing.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
jaimelopez
October 22nd, 2001, 05:43 AM
My application has to run at the same time that other applications that use these keys (like AS400 emulation). I thought I could use these keys because the users are used to work with them and it is more confortable for them when I keep something from the "old" application. So they should be able to use these keys along the whole application. But I think I will use your first suggestion (in fact there are not so many child forms and in future this will not change, the number of forms).
Jaime
JHamilton
October 22nd, 2001, 05:45 AM
What I was going to suggest is creating a menu on your MDI form that has a binding to F5.
Software is like sex, it's better when it's free - Linus Torvalds
Software is like sex, it's better when I get paid for it. - me
Clearcode
February 28th, 2002, 08:24 AM
The new release of the MCL Hotkey control has an enabled property so you can turn the hotkey on and off when your app is minimised/maximised.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com/EventVB/Overview.htm - Flatten the API learning curve
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.