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.
--
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.