 |
 |

08-15-2004, 04:33 PM
|
 |
Contributor
|
|
Join Date: May 2004
Location: Ohio, USA
Posts: 771
|
|
To HotKey, or Not to HotKey?
|
how would I go about having a function or sub that is always waiting for specific keys to be pressed?
Lets say CTRL + O to open a file, like in many Windows apps. How can I program for this event?
|
__________________
Brandon
Once you embrace the idea that your customers deserve to die...
...it frees your mind to invent splendidly profitable products - Dogbert
|

08-15-2004, 04:44 PM
|
|
Contributor
|
|
Join Date: Jul 2003
Posts: 741
|
|
|

08-15-2004, 06:15 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
|
Or, to cheat, you can use the Menu Editor, but make the menu invisible - the hotkeys would still work. Then in the Click event for the menu with the Hotkey that you've set up, you do what you want - this way you'd have it without the API method. Also, you can just check in the KeyDown sub (Shift = vbCtrlMask and KeyCode = vbKeyO - but make sure KeyPreview is set to true for the form.)
|
|

08-15-2004, 08:00 PM
|
 |
Contributor
|
|
Join Date: May 2004
Location: Ohio, USA
Posts: 771
|
|
|
Thanks for both replies. I decided to use the HotKeys API method. Wasnt sure if there was any easier way of doing it. Might be eaiser ways, but I know, and am comfortable with, HotKeys API.
|
__________________
Brandon
Once you embrace the idea that your customers deserve to die...
...it frees your mind to invent splendidly profitable products - Dogbert
|

08-15-2004, 08:24 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
If it's just for your form, then yes, the hotkeys API is way overkill... This works just as well:
Code:
'Be sure to set the KeyPreview property of the form to True
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyO And Shift = vbCtrlMask Then
MsgBox "Ctrl+O pressed."
End If
End Sub

|
|

08-15-2004, 08:50 PM
|
 |
Contributor
|
|
Join Date: May 2004
Location: Ohio, USA
Posts: 771
|
|
|
Set to true, and that code is not doing anything. I have never used this peice of code before.
Something I am faced with now, that I have never had to do before....How to register 2 (or more) hotkeys to run in the same time. Like CTRL+O & CTRL+P & CTRL+S...just like in most microsoft programs. I have used hotkeys before, but never had to have more than one at any given time. I just tried doing so, and go errors.
|
__________________
Brandon
Once you embrace the idea that your customers deserve to die...
...it frees your mind to invent splendidly profitable products - Dogbert
|

08-15-2004, 10:30 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
|
Well, in that case, try using the Menu Editor option that I outlined earlier - it makes for less messy API stuff that you have to remember to Unregister later on.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|