If I understand the filter-by-window in keyboard.registerHotkey
technique correctly, you would need to be careful that the window
you're watching does not come and go, such as when it's part of a
dialog.  Window handles generally remain valid unless they fall within
something that can close.

Another thing to watch out for, in some applications anyway, is the
possibility of multiple MDI windows.  Applications such as Word that
can show multiple files at once are good examples.  The approach of
hooking OnChildFocus/Blur at the application window level would work
best for those, because you can then check for class/module and grab
all MDI child windows of interest rather than accidentally hooking the
first one that opens and missing the rest, or forgetting one when
another opens, etc.

On Wed, Sep 03, 2008 at 09:54:15AM -0400, Aaron Smith wrote:
Ron reminded me that Keyboard.RegisterHotkey also takes a filter 
parameter that lets you specify the window you want your registered 
hotkey to apply to. So if you have the editor window object, you could do:

Set myF8Key = Keyboard.RegisterHotkey("F8", "BeginSelect", theEditorWindow)
Set myShiftF8Key = Keyboard.RegisterHotkey("Shift-F8", "EndSelect", 
theEditorWindow)

Then those keys would only work in that specific window.

Aaron

Aaron Smith wrote:
>Charles Steyn wrote:
>>Thanks very much for your comments. I'll experiment further. I'll have
>>to get the handling of the OnChildFocus and OnChildBlur events right
>>before my script really would work correctly.
>
>It'd go something like this:
>
>Dim theEditorWindow : Set theEditorWindow = <a window object 
>representing the editor window>
>
>ConnectEvent theEditorWindow, "OnChildFocus", "RegisterMyKeys"
>ConnectEvent theEditorWindow, "OnChildBlur", "UnregisterMyKeys"
>
>Sub RegisterMyKeys(windowObj)
>    ' Register your keys here
>End Sub
>
>Sub UnregisterMyKeys(windowObj)
>    ' Unregister your keys here
>End Sub
>
>How you find the editor window is up to you. In Studio 2008, the module 
>name is MSENV, and the class name is VsTextEditPane. You could use the 
>Window object's FilterByClassAndModule to search for that window, and if 
>you find it, then hook your events (in that case, you'd use OnFocus and 
>OnBlur rather than the child events because you are only interested in 
>that one window). Alternatively, you could hook the main application 
>window when the script starts, and then look for the right class name in 
>your register/unregister subs. That would go a little something like this:
>
>ConnectEvent ClientInformation.Overlap, "OnChildFocus", "RegisterMyKeys"
>ConnectEvent ClientInformation.Overlap, "OnChildBlur", "UnregisterMyKeys"
>
>Sub RegisterMyKeys(windowObj)
>    If windowObj.ClassName = "VsTextEditPane" Then
>        ' Register your keys here
>    End If
>End Sub
>
>Sub UnregisterMyKeys(windowObj)
>    If windowObj.ClassName = "VsTextEditPane" Then
>        ' Unregister your keys here
>    End If
>End Sub
>
>The second method is a bit more work, but it's another example of how to 
>skin this cat.
>
>Aaron

-- 
Doug Lee, Senior Accessibility Programmer
SSB BART Group - Accessibility-on-Demand
mailto:[EMAIL PROTECTED]  http://www.ssbbartgroup.com
"While they were saying among themselves it cannot be done,
it was done." --Helen Keller

Reply via email to