Hi Chip: I eliminated the class "Tester" all together and moved the functions 
into the main class so there would be no instantiation required.
The definitions are set up in the Initialization Sub now as are the other 
WindowEyes objects.
The Speech works fine, I think the quit function is working and in a prior test 
many weeks, months? ago the MSAA tests Aaron had sent me code for worked using 
this method without any Module (Global) Variable handlers getting garbage 
collected as the initialization sub lost focus.
That is because these types of variables are actually classes behind the scenes 
and any objects associated with the class are held until the underlying class 
is no longer needed according to Microsoft.
I have only one last idea and that is the timing, threading, problem Bruce has 
come up with.
His idea is to run each event handler on it's own thread so the messages dont 
somehow step on each other due to timing issues if I understand him correctly.
This is getting pretty close to defining the problem as one which GW should 
address while performing the message processing between my script, the 
underlying application and WindowEyes but I  may give it a try as a last ditch 
effort to get it working.
My guess is that if there is a threading problem as a result of timing or any 
other reason that it is not a matter of running my script's event handlers on a 
seperat thread since the messages are propagated among at least 2 other threads 
and apartments which can not be addressed from within my script if I understand 
the process - no pun intended.
  So, I am now pretty sure it is not a scope problem since I have eliminated 
the possibility of the scope issue you pointed out and other WindowEyes 
handlers work and are not lost within the current code block.
  The only diference seems to be that there are 2 handlers associated with the 
one Keyboard object used in my program. 
  I have used the Speech.Speak method and the Speach.OnSpeak Event handler and 
both work fine using the same code as I have used with the OnKeyUp and 
OnKeyDown event handlers which dont work properly.
  Again, since flipping which order I put the AddHandler statements in 
determines which handler gets eexcuted and which is not executed I am leaning 
twoard Bruce's idea of this being related to thread processing timing and, or, 
a message threading issue between the various threads and apartments.
  I will have to do some reading on running seperat event handlers on seperat 
threads. I think Bruce sent me a MSDN article on doing this for some UIA 
operations and will have to study up on it.
  I know how tr run background threads but I'm not sure this is what is 
required, sigh.
  Later and thanks for all the massive dialog on this problem.
  Rick USA
  From: Chip Orange 
  To: [email protected] 
  Sent: Friday, June 22, 2012 1:42 PM
  Subject: RE: OnKeyUp and OnKeyDown test using Excel type delegate assignment


  Rick,

  It still looks to me as though you are creating a new object (with the "new 
initProc" statement), which immediately handles the initialization you want, 
but then just as soon goes out of context becaust you aren't assigning it to a 
global variable.  I think therefore, you've still got everything going 
immediately out of scope.

  I'd be curious if you assigned new init proc to a global variable, if that 
made any difference.
  Also, a small thing, but I'd wait for all keys to be up before I tried to 
hook their events, not afterwards.  Afterwards might mean you'll be coming in 
in the middle of a key press event, and only returning a value for the up 
stroke.

  Chip




----------------------------------------------------------------------------
    From: RicksPlace [mailto:[email protected]] 
    Sent: Friday, June 22, 2012 5:18 AM
    To: [email protected]
    Subject: OnKeyUp and OnKeyDown test using Excel type delegate assignment


    Hi Guys:
    I found an Excel example of using what appears to be delegates and set up 
my code to match the delegate portion of the code using the WindowEyes handlers 
exposed in the error message noted in the prior post.
    The underlying target application, vb.net 2010 express, still seems to lock 
up as it did using the native AddHandler statements.
    Any ideas from this code snipet?
    Am I doing everything all wrong, is there a bug in WindowEyes? I dont know 
what to try or where to turn next.

    Here is the relative code in my program 
    Note: weApplication is assigned to WindowEyes.Application
    Public Module LaunchApp
    Public EventDel_OnKeyDownEventHandler As 
WindowEyes.KeyEvents_OnKeyDownEventHandler
    Public EventDel_OnKeyUpEventHandler As 
WindowEyes.KeyEvents_OnKeyUpEventHandler
    Public Sub Main()
    Application.Run(New InitProc)
    End Sub
    End Module    
    Public Class InitProc
    Inherits ApplicationContext
    Public Sub New()
    EventDel_OnKeyDownEventHandler = _
    New WindowEyes.KeyEvents_OnKeyDownEventHandler( AddressOf OnKeyDownHandler) 
    EventDel_OnKeyUpEventHandler = _
    New WindowEyes.KeyEvents_OnKeyUpEventHandler( AddressOf OnKeyUpHandler) 
    AddHandler weApplication.Keyboard.OnKeyDown, EventDel_OnKeyDownEventHandler 
    AddHandler weApplication.Keyboard.OnKeyUp, EventDel_OnKeyUpEventHandler 
    weApplication.Keyboard.WaitForAllKeysUp()
    End Sub
    Public Function OnKeyDownHandler( _
    ByVal ReturnedKey As Integer, ByVal ReturnedModifiers As 
WindowEyes.KeyModifiers) _
    As WindowEyes.KeyDisposition
    Dim AppropriateDisposition As WindowEyes.KeyDisposition
    AppropriateDisposition = WindowEyes.KeyDisposition.kdProcess
    Return AppropriateDisposition
    End Function
    Public Function OnKeyUpHandler( _
    ByVal ReturnedKey As Integer, ByVal ReturnedModifiers As 
WindowEyes.KeyModifiers) _
    As WindowEyes.KeyDisposition
    Dim AppropriateDisposition As WindowEyes.KeyDisposition
    AppropriateDisposition = WindowEyes.KeyDisposition.kdProcess
    Return AppropriateDisposition
    End Function
    End Class
    Public Class ScriptLog
    Public Shared Sub WriteLine( ByVal Line As String )
    Dim ThisFilePath As String = _
    Globals.ProjectDirectoryPath & _
    "\ScriptLog.txt"
    Try
    File.AppendAllText( ThisFilePath, Line )
    File.AppendAllText( ThisFilePath, vbCrLf )
    Catch ex As Exception
    MessageBox.Show( "Exception in ScriptLog, " & ex.ToString() )
    End Try 
    End Sub
    Public Shared Sub Clear()
    Dim ThisFilePath As String = _
    Globals.ProjectDirectoryPath & _
    "\ScriptLog.txt"
    File.Delete(ThisFilePath)
    WriteLine( DateTime.Now )
    End Sub

    End Class

Reply via email to