I have a application that I will be using in Full Screen mode and need to capture anytime the mouse is moved or a key is pushed so i can turn off this applications "screen saver" so the user can start to use the system. I do not need to know where the mouse is located or what key is pressed.
Searching the internet I found the following class that I guess handles this but I am not sure how to use this in my application and return to my application that the mouse was moved or a key was pressed.
I added a class to my Project called "MouseHook" and below is the entire text inside that class.
Code:Imports System.Runtime.InteropServices Public Class MouseHook ' DECLARATION Public Event KeyPressed(ByVal KeyChar As Int32) Delegate Function HookProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr Declare Auto Function SetWindowsHookEx Lib "user32.dll" (ByVal idHook As Integer, ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As Integer) As IntPtr Declare Function UnhookWindowsHookEx Lib "user32.dll" (ByVal hhk As IntPtr) As Boolean Declare Function CallNextHookEx Lib "user32.dll" (ByVal hhk As IntPtr, ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr Const WH_KEYBOARD_LL As Integer = 13 Shared KeyBoardHook As IntPtr Public Function MyLLKbdProc(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr RaiseEvent KeyPressed(Marshal.ReadInt32(lParam)) Return CallNextHookEx(KeyBoardHook, nCode, wParam, lParam) End Function Public Sub KeyBoardListen() Dim hp1 As HookProc = AddressOf MyLLKbdProc KeyBoardHook = SetWindowsHookEx(WH_KEYBOARD_LL, hp1, Marshal.GetHINSTANCE(GetType(MouseHook).Module), 0) GC.KeepAlive(hp1) End Sub Public Sub KeyBoardStopListen() UnhookWindowsHookEx(KeyBoardHook) End Sub End Class




Reply With Quote