Hi Rick,
 
Before trying to read through all the work you've done; I can start of
suggesting that the best approach is for you to register a cursor key (don't
get confused with cursor keys defined in a WE set file, not really the same
thing).
 
When you know the user has activated the solution explorer (which is where I
think you want this to happen), then define a cursor key for shift-escape.
Also, add an event handler for the solution explorer which tracks if it
closes or loses activation (in these case you then need to unregister your
cursor key).
 
Now, you have a cursor key which is only defined when the solution explorer
is active, so you don't have to do a lot of testing in its handler to see if
things are right; you know its ok to do your processing in the cursor key
callback for this key.
 
Assuming you have a global object variable to hold your registered cursor
key, and assuming you have the window object for the solution explorer
window stored in a variable, below is a VBS suggestion for registering a
cursor key, which I think you will be easily able to translate into all the
vb.net code (which would run when the solution explorer gets
activation/focus):
 
set myCursorKey = keyboard.registerCursorKey("shift-escape",
"myCursorKeyHandler", solutionExplorerWindow)
' and also define event handler for the solution explorer window losing
focus/activation, hiding, etc.
 
sub myCursorKeyHandler()
' in here do what you need to (give some other window the focus?)
 
end sub
 
 
How does this sound as a start?
 
Chip
 
 


  _____  

From: RicksPlace [mailto:ofbgm...@mi.rr.com] 
Sent: Thursday, June 07, 2012 10:39 AM
To: gw-scripting@gwmicro.com
Subject: GW Object Model And KeyProcessed Problem Full Test


Hi Guys:
To determine if there is a bug in WindowEyes Or, if I am doing something
wrong...
Lets start from the beginning:
The most simple case:
In my script I want to trap when a user hits Shift-Escape in the Target
Application and let it process normally as if it was not trapped by my
script.
Once this works I will want to do something with the Speech.Speak WE Object
Method but not yet for testing.
 
Below are the steps I used and the source code:
Steps 1-3 are functional analysis of WE Docs and Objects to pick and use:
Step4) Extracted Code Blocks
Step5) Results
Step6) Summary
Step7) Full SourceCode:
Please let me know if this appears to be a bug in WindowEyes or am I doing
something wrong?
 
Step1)
Reading the following WE Docs it sounds like the 
Objects
 >
Key
 >
Events
 >
OnKeyProcessedDown
event would accomplish this.
Does this sound correct so far?
Here is the WE Docs on this event:
Navigation:
The Window-Eyes Object Model
 >
Objects
 >
Key
 >
Events
 >
OnKeyProcessedDown
Previous page
Return to chapter overview
Next page
Occurs when a key is pressed and processed. You cannot modify the behavior
of the
key press during this event.
For security purposes, key events will not fire when a password edit box has
focus.
Syntax
Sub OnKeyProcessedDown(
VirtualKeyCode
,
KeyModifiers
)
Parameters
Name
Data Type
Description
VirtualKeyCode
Long
The value of the key that was passed to the event
KeyModifiers
Enum
Key modifiers that were passed to the event
Step2)
Now, I just use the key combination "Shift-Escape" as defined below instead
of using a single key (Escape) and a modifier since that is not how the WE
docs describe using this object in the below documents.
So, the next Object I look at is the "Key" object:
Navigation:
The Window-Eyes Object Model
 >
Objects
 >
Key
Previous page
Return to chapter overview
Next page
Definition
An object representing a keyboard key.
Usage
Use a
Key
 object to retrieve information about a keyboard key. A
Key
 object can be obtained from a
Keyboard
 object's
Key
, or
Capture
 method, or from a
Keys
 object's
Item
 method.
Properties
.
Application
.
Down
.
FilterActiveWindow
.
FilterAlt
.
FilterApplication
.
FilterControl
.
FilterFocusedWindow
.
FilterInsert
.
FilterNumlock
.
FilterNumpad
.
FilterProcess
.
FilterShift
.
FilterWindows
.
Index
.
Name
.
Parent
.
RequiredModifiers
.
Toggled
.
UntranslatedName
Methods
.
Insert
.
RequireModifiers
Events
.
OnKeyDown
.
OnKeyProcessedDown
.
OnKeyProcessedUp
.
OnKeyUp
So, it appears the above Key object has the OnKeyProcessedDown method I
want.
Am I still on track with picking the correct objects for the job?
The docs say I can get one from the Key method of the Keyboard Object so
that is next.
Step3)
Navigation:
The Window-Eyes Object Model
 >
Objects
 >
Keyboard
 >
Methods
 >
Key
Previous page
Return to chapter overview
Next page
Returns a
Key
 object from a string name.
Syntax
Set object_variable = object.Key(KeyName)
where object is a
Keyboard
 object.
Parameters
Name
Data Type
Required/Optional
Description
KeyName
String
Required
The quoted string containing the name of a key (i.e. "Control-Shift-Q").
Modifiers
are spelled out completely, not abbreviated. You can use the Window-Eyes hot
key
dialog to verify the exact spelling of a hot key to use as a string. To
create an
Undefined key, use an empty string (i.e. "").
 
Since the example shows using a compound string ("Control-Shift-Q")
I use "Shift-Escape" as the string to define the Key Object I want in the
Keyboard Key method.
Step4) Extracted Code Blocks
Here is the extracted code in my script to accomplish the above, the full
code is below:
' Define the WE Key Object for Shift-Escape 
Public ShiftEscapeKey As WindowEyes.Key
' Assign the ShiftEscape Key
' I will put modules we test in the Tester Class for easy finding.
Dim instTester As New Tester
Try
ShiftEscapeKey = weApplication.KeyBoard.Key( "Shift-Escape" )
AddHandler ShiftEscapeKey.OnKeyProcessedDown, AddressOf
instTester.OnKeyProcessedDownSub
Catch ex As Exception
ScriptLog.WriteLine( "Catch Triggered assigning ShiftEscapeKey Handlers")
ScriptLog.WriteLine( ex.ToString())
End Try
In the Tester Class:
Public Sub OnKeyProcessedDownSub(ByVal ReturnedKey As Integer, ByVal
ReturnedModifiers As WindowEyes.KeyModifiers)
MethodID = "OnKeyProcessedDownSub"
ScriptLog.WriteLine( "Enter " & ClassID & " > " & MethodID)
ScriptLog.WriteLine( "ReturnedKey: " & ReturnedKey.ToString())
ScriptLog.WriteLine( "ReturnedModifiers: " & ReturnedModifiers)
mySpeech.Speak( "Key Down fired")
ScriptLog.WriteLine( "Exit " & ClassID & " > " & MethodID)
End Sub
Step5) Results
Here is the results when I run vb.net 2010 express and hit shift-escape with
Solution Explorer opened (Shift-Escape is suppose to "Hide" it.
Without the Shift-Escape WE Key object I see it disappear but with the WE
Key Object it does not disappear.
Here is the output from the handler sub:
Enter Tester > OnKeyProcessedDownSub
ReturnedKey: 27
KeyModifiers: kmShift
Exit Tester > OnKeyProcessedDownSub
>From Virtual Enumerations:
vk_SHIFT
0x10
dec: 16
vk_ESCAPE
0x1B
dec: 27
>From KeyModifiers Enumerations:
kmShift
1
Shift
Step6)
Summary:
The Shift-Escape proc is firing properly and appears to contain the correct
values upon firing.
A sighted person said that when the Shift-Escape handler is not enabled, I
just commented out the code in the Try  block, Solution Explorer is hidden
when I press Shift-Escape.
But, when I remove the comment "'" and let it run the Solution Explorer is
not hidden when I press Shift-Escape even though the Handler sub is firing
correctly.
I do note that the value of the KeyModifiers for the ShiftKey is a value of
1 while the virtual code is 16.
Likely this has nothing to do with anything but I not it since they are
diferent.
Step7) Full SourceCode:
' V 1.0
Imports System.Threading
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Configuration
Imports System.IO
Imports System.Windows
Imports System.Windows.Point
Imports System.Windows.Automation
' This is the Root Module.
' Anything defined here is global to the project.
Public Module LaunchApp
Public weApplication As WindowEyes.Application
    Public WithEvents weClientInformation As WindowEyes.ClientInformation
Public mySpeech As WindowEyes.Speech
' Define the WE Key Object for Shift-Escape 
Public ShiftEscapeKey As WindowEyes.Key
' This is the sub executed when VB.net 2010 Express is loaded.
Public Sub Main()
Application.Run( New ProjectContext)
End Sub
End Module    
Public Class ProjectContext
Inherits ApplicationContext
Dim ClassID As String = "ProjectContext"
Dim MethodID As String = ""
Public Sub New()
MethodID = "New()""
InitializeWindowEyesObjectss()
If Globals.FatleError Then GoTo ProcExit
' Assign the ShiftEscape CursorKey
' I will put modules we test in the Tester Class for easy finding.
Dim instTester As New Tester
Try
ShiftEscapeKey = weApplication.KeyBoard.Key( "Shift-Escape" )
AddHandler ShiftEscapeKey.OnKeyProcessedDown, AddressOf
instTester.OnKeyProcessedDownSub
Catch ex As Exception
ScriptLog.WriteLine( "Catch Triggered assigning ShiftEscapeKey Handlers")
ScriptLog.WriteLine( ex.ToString())
End Try
ProcExit:
If Globals.FatleError Then
weClientInformation_OnShutdown()
End If
End Sub
Public Sub InitializeWindowEyesObjectss()
MethodID = "InitializeWindowEyesObjectss()"
Dim AppProcess As Object = Nothing
Try
weApplication = New WindowEyes.Application
mySpeech = weApplication.Speech
weApplication.ClientIdentify(System.Diagnostics.Process.GetCurrentProcess().
Id)
weClientInformation = weApplication.ClientInformation
AddHandler weClientInformation.OnShutdown, AddressOf
weClientInformation_OnShutdown
AppProcess = weClientInformation.ApplicationProcess
Catch ex As Exception
ScriptLog.WriteLine( "Catch Triggered in " & ClassID & " > " & MethodID &
VbCrlf & ex.ToString())
Globals.FatleError = True
GoTo ProcExit
End Try
' Test to see if vb.net 2010 or vb.net 2008 is running.
' They both fire this script when started.
Dim VB2010 As Integer = 0
VB2010 = AppProcess.ProductName.IndexOf( "2010")
If VB2010 < 0 Then
mySpeech.Speak( "AppProcess.ProductName Not For 2010, is: " &
AppProcess.ProductName)
ScriptLog.WriteLine( "AppProcess.ProductName Not For 2010, is: " &
AppProcess.ProductName)
Globals.FatleError = True
GoTo ProcExit
End If
ProcExit:
If Globals.FatleError Then
mySpeech.Speak( "A FatleError occured in the WindowEyes Script at: " & _
ClassID & " > " & MethodID & "Shutting the script down. Check ScriptLog")
End If
End Sub
Public  Sub weClientInformation_OnShutdown()
MethodID = "weClientInformation_OnShutdown()"
ScriptLog.WriteLine( "Enter " & ClassID & " > " & MethodID)
mySpeech.Speak( "ShuttingDown Bye Bye")
Application.Exit()
System.Environment.Exit(0)
End Sub
Public Function OnSpeak(OriginalString)
ProcExit:
OnSpeak = originalString
End Function
End Class
Public Class Tester
Dim ClassID As String = "Tester"
Dim MethodID As String = ""
Public Sub OnKeyProcessedDownSub(ByVal ReturnedKey As Integer, ByVal
ReturnedModifiers As WindowEyes.KeyModifiers )
MethodID = "OnKeyProcessedDownSub"
ScriptLog.WriteLine( "Enter " & ClassID & " > " & MethodID)
ScriptLog.WriteLine( "ReturnedKey: " & ReturnedKey )
ScriptLog.WriteLine( "KeyModifiers: " & ReturnedModifiers.ToString() ) 
mySpeech.Speak( "Key Down fired")
ScriptLog.WriteLine( "Exit " & ClassID & " > " & MethodID)
End Sub
End Class


Reply via email to