Hi Doug and Aaron, I can now see what context I should be using this parameter. Thanks much. Warm regards. Martin Webster.
--- On Tue, 2/14/12, Doug Geoffray <geoff...@gwmicro.com> wrote: > From: Doug Geoffray <geoff...@gwmicro.com> > Subject: Re: help with FilterBy parameter > To: gw-scripting@gwmicro.com > Date: Tuesday, February 14, 2012, 6:16 PM > Martin, > > To add to Aaron's comment... > > I'm assuming this is a Notepad specific app, meaning not > global. I'm also assuming you only want your hotkey to > speak "this is notepad" if and only if focus is in the edit > box of Notepad and nowhere else in Notepad. If all > this is true then you could do: > > Begin VBScript: ' keyboard example using the FilterBy > parameter Dim myHotkey > > ' keyboard example using the FilterBy parameter > Dim myHotkey > Dim myFilter > > set myFilter = > ActiveWindow.Children.FilterByClassAndModule("Edit", > "NOTEPAD") > if myFilter.Count<> 1 then > Speak "Can't find the Notepad edit box, aborting!" > else > Set myHotkey = Keyboard.RegisterHotkey("h", "HandleKey", > myFilter(1)) > end if > > Sub HandleKey() > Speak "this is notepad" > End Sub > > > Doug > > On 2/14/2012 12:52 PM, Aaron Smith wrote: > > According to the documentation: > > > > FilterBy > > Object > > Optional > > Window object or Process object to filter the hot key > by. If the hot key should work globally (across all > applications), use Nothing as the FilterBy parameter, or > leave it empty. > > > > So if you're not checking the value of your > FilterByClassAndModule call, and it's returning Nothing, > then you're passing Nothing to the RegisterHotkey call, > meaning that the hot key should work everywhere. > > > > You'll also note that FilterByClassAndModule always > returns a Windows collection, so in your example below, > you're passing a Windows collection to a method that wants > either a single Window object, or a Process object, so > that's doomed from the start. I would set the result of > FilterByClassAndModule to a variable, and ensure that it has > but one window in it before passing that Window object on to > the RegisterHotkey method. > > > > Aaron > > > > > > On 2/14/2012 12:38 PM, martin webster wrote: > >> Hi Aaron, > >> So what's the point of the FilterBy parameter > then?. There is something I'm not understanding. > >> Warm regards. > >> Martin Webster. > >> > >> > >> --- On Tue, 2/14/12, Aaron Smith<aa...@gwmicro.com> > wrote: > >> > >>> From: Aaron Smith<aa...@gwmicro.com> > >>> Subject: Re: help with FilterBy parameter > >>> To: gw-scripting@gwmicro.com > >>> Date: Tuesday, February 14, 2012, 4:49 PM > >>> Martin, > >>> > >>> You should create (and check the value of) a > variable that > >>> holds the result of > >>> > >>> > ActiveWindow.Children.FilterByClassAndModule("Edit", > >>> "NOTEPAD") > >>> > >>> because it may come back with Nothing. If you > end up passing > >>> Nothing as the FilterBy parameter, you're > effectively > >>> registering a global hotkey that will execute > anywhere. > >>> > >>> Aaron > >>> > >>> > >>> On 2/14/2012 11:36 AM, martin webster wrote: > >>>> Hi All, > >>>> I am trying to use the FilterBy parameter > of the > >>> registerHotkey property and it doesn't seemed > to work for > >>> me. The following snippet should be able to > detect that the > >>> notepad window is active and say "this is > notepad" only and > >>> only when the notepad window is active, but at > present this > >>> snippet says "this is notepad" when any > application is > >>> active. I only want the hotkey to fire when > notepad is > >>> active, so how do I set this parameter. > >>>> Begin VBScript: > >>>> ' keyboard example using the FilterBy > parameter > >>>> Dim myHotkey > >>>> Set myHotkey = > Keyboard.RegisterHotkey("h", > >>> "HandleKey", > >>> > ActiveWindow.Children.FilterByClassAndModule("Edit", > >>> "NOTEPAD")) > >>>> Sub HandleKey() > >>>> Speak "this is notepad" > >>>> End Sub > >>>> Warm regards. > >>>> Martin Webster. > >>> -- Aaron Smith > >>> Web Development * App Development * Product > Support > >>> Specialist > >>> GW Micro, Inc. * 725 Airport North Office Park, > Fort Wayne, > >>> IN 46825 > >>> 260-489-3671 * gwmicro.com > >>> > >>> To insure that you receive proper support, > please include > >>> all past > >>> correspondence (where applicable), and any > relevant > >>> information > >>> pertinent to your situation when submitting a > problem report > >>> to the GW > >>> Micro Technical Support Team. > >>> > >>> > > > >