This message roughly demonstrates the process of binding a hotkey. Essentially, you define a global variable for each desired hotkey. While that variable contains the result of a Keyboard.RegisterHotkey call, the hotkey exists.
A common way to keep all hotkeys together is to use the WSH Scripting.Dictionary object. There is also an object provided in the GW Toolkit script which simplifies the process of binding hotkeys and provides an easy mechanism for a user to redefine them. For the best example of this, take a look at the latest version of the virtual view script: http://www.gwmicro.com/scripts/VirtualView Hope this helps. Darren ---------- Forwarded message ---------- From: [EMAIL PROTECTED] Date: Fri, 15 Aug 2008 16:08:47 +0100 Subject: Re: I need an example To: [email protected] Hello Martin, I'll do my best. Here's an example which I've just tried, and got to work. Option Explicit Dim myKey : Set myKey = Keyboard.RegisterHotKey("Control-R", "SpeakHelloWorld", , , True) Dim eventShutdown : eventShutdown = ConnectEvent (ClientInformation, "OnShutdown", "OnShutdown") Sub SpeakHelloWorld(firstPress) If firstPress Then Speak "this is the first time you pressed" Else Speak "Key pressed twice" End If End Sub Sub OnShutdown() Speak "Goodbye" myKey.UnRegister Set myKey = Nothing Disconnect eventShutdown End Sub ' end example Some of those lines probably wrap, so watch out for that. Your function should probably be a sub routine, since it doesn't return anything. The only problem I could find with your code was the first line after function SpeakHelloWorld(firstPress) Just go straight into the conditional statement If firstPress Then Speak "this is the first time you pressed" Else Speak "Key pressed twice" End If There is a chance that since you didn't first declare the myKey variable before attempting to use it, VBScript didn't like it. So, just to be on the safe side, I've declared that in my example. You'll also see the addition of the OnShutdown procedure, and the eventShutdown variable. This is just so we can clean up after ourselves and ensure that the hotkey is released when the script unloads. Window-Eyes does do this anyway, but it does no harm to release our memory footprint ourselves <grin>. Hope this helps. GOod luck! Darren On 15/08/2008, martin webster <[EMAIL PROTECTED]> wrote: > Hi all and Aaron, > I need to no why in the below example why I have to press any key before the > routine will toggle back to true, and if there's anyway I can prevent this > as I just want the routine to toggle with out this behavour. I have tried > to return firstPress as True back to the calling point but it doesn't work > until I press any other key on the keyboard. I have removed the line of > code that attempt to return firstPress as True because it didn't make any > difference. If this is not the correct way of doing this, can somebody tell > me what is. > ' Detect if a key has been pressed twice in succession > Set myKey = Keyboard.RegisterHotKey("Control-R", "SpeakHelloWorld", , , > True) > Function SpeakHelloWorld(firstPress) > Speak firstPress > If firstPress Then > Speak "this is the first time you pressed" > Else > Speak "Key pressed twice" > End If > End Function > > > Warm regards. > Martin Webster. > > > > >
