Hello everyone!
I'm working with Windows 7 and my application is having some troubles with the SetWindowsHookEx API - everything works fine but when my application is not responsive (gets into a loop) the hook automatically stops (LowLevelHookTimeOut) thats because my application haven't processed the hook messages in time (In this case, mouse movements).
When I install the hook a method called "MouseProc" gets the hook messages (mouse movements and clicks) the problem is that this method ("MouseProc") is on the same thread of my app UI - is there is any way to make the "MouseProc" method be on a separate thread? I have attached the class.
When the user declares this class as new the hook is automaticlly installed, here is an example:
I thought calling the API in another thread when the class being declared as new:Code:Dim WithEvents MHook As MouseHook Private Sub Form_Load(Some Args) MHook = New MouseHook() 'Mouse hook installed End Sub
But it's not really working.Code:Public Sub New() Dim t as New Thread(AddressOf InstallHook) t.Start() End Sub Private Sub InstallHook() ''Installs a Low Level Mouse Hook MouseHookDelegate = New MouseProcDelegate(AddressOf MouseProc) MouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookDelegate, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0) End Sub
Thank you and hope a solution will be found... I tried different stuff but nothing really works yet....




Reply With Quote