|
-
Apr 8th, 2001, 11:13 PM
#1
Hi, guys....I am new here and need some help.
I am trying to create a program that will disable the keyboard and mouse and then enable them back.
My program will run under windows 95, so the API BlockInput will not work. And, my program should be able to disable the keyboard and mouse even when my program is not on focus (because my program will call other application and simulate some keystrokes, which will cause other applications to gain focus).
I had tried the following code, but it is not working. Something's wrong...?
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
g_hMouseHook = SetWindowsHookEx(WH_MOUSE, AddressOf MouseProc, App.hInstance, App.ThreadID)
g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
Sleep 5000
If g_hMouseHook Then
Call UnhookWindowsHookEx(g_hMouseHook)
g_hMouseHook = 0
End If
If g_hKeyboardHook Then
Call UnhookWindowsHookEx(g_hKeyboardHook)
g_hKeyboardHook = 0
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''
'API Constants
Public Const WH_KEYBOARD As Long = 2
Public Const WH_MOUSE As Long = 7
'API Declarations
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'Global mouse/keyboard function callback handles
Public g_hMouseHook As Long
Public g_hKeyboardHook As Long
Public Function MouseProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Mouse Function Hook...
If idHook < 0 Then
MouseProc = CallNextHookEx(g_hMouseHook, idHook, wParam, ByVal lParam)
Else
'Setting the return value to -1 cancels Mouse input...
MouseProc = -1
End If
End Function
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Keyboard Function Hook...
If idHook < 0 Then
KeyboardProc = CallNextHookEx(g_hKeyboardHook, idHook, wParam, ByVal lParam)
Else
'Setting the return value to -1 cancels Keyboard input...
KeyboardProc = -1
End If
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''
Or is there any better suggestion...?
By the way, I am using VB5
Thank you.
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
|