Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code to disable both keyboard and mouse temporarily
#9
Hi Gintaras

You sent me the following code 2 years ago which worked well then. But now I am trying to run it under Win2000 on QM 2.16 and it doesn't work. The mouse becomes very slow and jumpy but not frozen. I have not tried the keyboard.

You may recall that I do not want the students to be able to use Ctrl-Alt-Del to defeat the code.

Grateful for any help you can give.

Alistair


Gintaras Wrote:On Windows 98/Me, we can easily disable Ctrl+Alt+Delete. On other OS, we cannot disable it, but can install low level hooks to filter keyboard and mouse input.

Note: the attached file contains newer versions of these functions. Just import and use.

Function BlockInput2:
Code:
Copy      Help
function block

;Blocks keyboard and mouse input so that Ctrl+Alt+Delete cannot unblock.

;EXAMPLE
;opt waitmsg 1
;BlockInput2 1
;60
;BlockInput2 0


dll user32 #SetWindowsHookEx idHook lpfn hmod dwThreadId
dll user32 #UnhookWindowsHookEx hHook
dll user32 #CallNextHookEx hHook ncode wParam !*lParam
type KBDLLHOOKSTRUCT vkCode scanCode flags time dwExtraInfo
type MSLLHOOKSTRUCT POINT'pt mouseData flags time dwExtraInfo
def WH_KEYBOARD_LL 13
def WH_MOUSE_LL 14
def SPI_SETSCREENSAVERRUNNING 0x0061

if(_winnt)
,int+ bikhook bimhook
,if(block)
,,if(bikhook) UnhookWindowsHookEx(bikhook)
,,if(bimhook) UnhookWindowsHookEx(bimhook)
,,bikhook=SetWindowsHookEx(WH_KEYBOARD_LL &BIKeyboardProc _hinst 0)
,,bimhook=SetWindowsHookEx(WH_MOUSE_LL &BIMouseProc _hinst 0)
,else
,,UnhookWindowsHookEx(bikhook); bikhook=0
,,UnhookWindowsHookEx(bimhook); bimhook=0
else
,SystemParametersInfo(SPI_SETSCREENSAVERRUNNING block &_i 0)
,BlockInput block

It also requires two other functions that filter input events on Windows 2000/XP. System calls them on keyboard and mouse input events.

BIKeyboardProc:
Code:
Copy      Help
;/
function nCode wParam KBDLLHOOKSTRUCT*lParam

if(nCode>=0)
,if(lParam.flags&16=0) ret 1

ret CallNextHookEx(bikhook nCode wParam lParam)

BIMouseProc:
Code:
Copy      Help
;/
function nCode wParam MSLLHOOKSTRUCT*lParam

if(nCode>=0)
,if(lParam.flags&1=0) ret 1

ret CallNextHookEx(bimhook nCode wParam lParam)


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)