|
-
Nov 8th, 2000, 09:51 AM
#1
Thread Starter
New Member
I would like to know if there is a way to disable the mouse and keyboard from within VB while a certain process runs, and then enable them again once complete. This must be system wide so the mouse and keyboard cannot bring focus to another application or anything.
Any help with this would be greatly appreciated since I have no idea of how to do this (or if it is possible).
Thanks in Advance
-
Nov 8th, 2000, 03:20 PM
#2
Code:
Shell "rundll32 mouse,disable"
Shell "rundll32 keyboard,disable"
-
Nov 15th, 2000, 08:35 AM
#3
New Member
Disabling Mouse and Keyboard
How can i able them again ???
-
Nov 15th, 2000, 09:32 AM
#4
New Member
What you actually should use is the SetWindowsHookEx API call.
You use this API call to replace the VB Mouse and Keyboard processing routines with your own,
then you can do what you want with the events...and you can easily restore the normal Keyboard and Mouse Event handlers
using the UnhookWindowsHookEx API call. Remember to restore the Mouse and Keyboard handlers or you app will crash.
Here's the code
The definitions...
Code:
'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
'Global mouse/keyboard function callback handles
Public g_hMouseHook As Long
Public g_hKeyboardHook As Long
The calls to set the Mouse and Keyboard Callback routines (can be done anywhere, Form, Class, Module)...
Code:
g_hMouseHook = SetWindowsHookEx(WH_MOUSE, AddressOf MouseProc, App.hInstance, App.ThreadID)
g_hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
The calls to reset the VB Mouse and Keyboard Callback routines (can be done anywhere, Form, Class, Module)...
Code:
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
NOW...your Mouse and Keyboard callback routines...these can ONLY be in a .BAS Code Module
Code:
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
-
Nov 15th, 2000, 03:37 PM
#5
To enable them.
Code:
Shell "rundll32 mouse,enable"
Shell "rundll32 keyboard,enable"
-
Nov 16th, 2000, 06:46 AM
#6
New Member
This is not working on my computer
This codes is not working on my computer:
Shell "rundll32 mouse,enable"
Shell "rundll32 keyboard,enable"
am i missing something ????
-
Nov 16th, 2000, 09:14 AM
#7
New Member
My suggestion is to use the code that I provided.
It gives you much more control over the Mouse and Keyboard input...and it works.
-
May 24th, 2002, 07:14 PM
#8
Member
this doesn't seem to work system wide... only on the vb app... is there someway to make it system wide (the vb code not the run blah blah, enable crap)
-
Dec 6th, 2002, 06:33 PM
#9
Lively Member
instead of app.threadid in the two api calls, type 0 make sur eu leave the comma and parenthesis there... just take out app.threadid and type 0
-
Dec 6th, 2002, 10:30 PM
#10
Fanatic Member
Dont you need to restart to enable input you blocked with
Shell "rundll32 mouse,disable"
Shell "rundll32 keyboard,disable"
-
Dec 7th, 2002, 08:27 AM
#11
PowerPoster
VB Code:
Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Activate()
'KPD-Team 2000
'URL: [url]http://www.allapi.net/[/url]
DoEvents
'block the mouse and keyboard input
BlockInput True
'wait 10 seconds before unblocking it
Sleep 10000
'unblock the mouse and keyboard input
BlockInput False
End Sub
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
|