Hi Rick, I think if it had anything to do with messages being lost due to timing issues, then your test with the speech object and two events which happen almost simultaneously would also have failed. I do find it very persuasive that you have other event handlers working (I thought I had asked this question before, and I thought you said you never really got any working). That's a powerful argument that there is a problem in the keyboard event handlers. At this point I'd write up an example (such as the onKey example I posted here), which only shows use of the onKey event handlers, and I'd email it to GW support, telling them it doesn't work for you (while other event handlers do), and why it doesn't work, and wait until you hear back from them. I know you may have done that here, but the list is too busy to be used for possible bug reporting, and so I think an email to support with a simple example is better. Chip
_____ From: RicksPlace [mailto:[email protected]] Sent: Saturday, June 23, 2012 5:41 AM To: [email protected] Subject: Re: OnKeyUp and OnKeyDown test using Excel type delegate assignment 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 <mailto:[email protected]> 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
