|
-
Aug 7th, 2007, 09:46 AM
#1
Thread Starter
New Member
[2005] Capturing Mouse & Keyboard Movements
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
-
Aug 7th, 2007, 09:47 AM
#2
Re: [2005] Capturing Mouse & Keyboard Movements
If your application is full-screen then presumably all you need to do is handle the built-in .NET events sent to your application's form; or am I missing something?
-
Aug 7th, 2007, 10:51 AM
#3
Thread Starter
New Member
Re: [2005] Capturing Mouse & Keyboard Movements
I am using the axWebBrowser control taking over the full screen so this way it pulls in the application where I can change it on the fly for all locations (this will be for a kiosk)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|