|
-
October 22nd, 2001, 03:56 AM
#1
simulating hotkey
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).
-
October 22nd, 2001, 04:31 AM
#2
Re: simulating hotkey
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
-
October 22nd, 2001, 04:47 AM
#3
Re: simulating hotkey
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.
-
October 22nd, 2001, 05:24 AM
#4
Re: simulating hotkey
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
-
October 22nd, 2001, 05:30 AM
#5
Re: simulating hotkey
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.
-
October 22nd, 2001, 05:43 AM
#6
Re: simulating hotkey
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
-
October 22nd, 2001, 05:45 AM
#7
Re: simulating hotkey
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
-
February 28th, 2002, 09:24 AM
#8
Re: simulating hotkey
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|