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
