Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > To HotKey, or Not to HotKey?


Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2004, 04:33 PM
Rashka's Avatar
Rashka Rashka is offline
Contributor
 
Join Date: May 2004
Location: Ohio, USA
Posts: 771
Default 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
Reply With Quote
  #2  
Old 08-15-2004, 04:44 PM
b0b b0b is offline
Contributor
 
Join Date: Jul 2003
Posts: 741
Default

RegisterHotKey and UnregisterHotKey, there are examples of how to use them in the links:

http://www.mentalis.org/apilist/RegisterHotKey.shtml
http://www.mentalis.org/apilist/UnregisterHotKey.shtml
Reply With Quote
  #3  
Old 08-15-2004, 06:15 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
Default

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.)
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #4  
Old 08-15-2004, 08:00 PM
Rashka's Avatar
Rashka Rashka is offline
Contributor
 
Join Date: May 2004
Location: Ohio, USA
Posts: 771
Default

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
Reply With Quote
  #5  
Old 08-15-2004, 08:24 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
Default

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
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #6  
Old 08-15-2004, 08:50 PM
Rashka's Avatar
Rashka Rashka is offline
Contributor
 
Join Date: May 2004
Location: Ohio, USA
Posts: 771
Default

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
Reply With Quote
  #7  
Old 08-15-2004, 10:30 PM
MikeJ's Avatar
MikeJ MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
Default

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.
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->