How do I use Win32 programming to turn off the keboard?

Started by
17 comments, last by dampe64 20 years, 6 months ago
quote:Original post by DerekSaw
quote:
how can you disable alt+tab in windows 98 ?

I suppose you want to hear about the famous "screen saver" trick?


quote:
how can you disable alt+tab in windows 98 ?

I suppose you want to hear about the famous "screen saver" trick?

Yeap, trick Windows into thinking that the screensaver is running... this also disables ALT+CTRL+DEL but ONLY works on Windows 9x.

UINT nPreviousState;
// Disables task switching SystemParametersInfo (SPI_SETSCREENSAVERRUNNING, TRUE, &nPreviousState, 0);
// Enables task switching SystemParametersInfo (SPI_SETSCREENSAVERRUNNING, FALSE, &nPreviousState, 0);

Windows NT 4.0 Service Pack 3 and later Windows 2000 Applications can disable ALT+TAB by installing a low-level keyboard hook. A low-level keyboard hook is installed by calling SetWindowsHookEx();

LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM lParam)
{
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam;
BOOL bControlKeyDown = 0;
switch (nCode)
{
case HC_ACTION:
{
bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1); // Disable CTRL+ESC
// Disable ALT+ESC
if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN)
return 1;
}
default:
break;
}
return CallNextHookEx (hHook, nCode, wParam, lParam);
}




Advertisement
You''re a genious Mr.Mystery!
Under XP you can call RegisterHotKey() but I''m not sure about other windows versions..
could you show me the code o call the LowLevelKeyProc with SetWindowsHookEx.
quote:Original post by Anonymous Poster
You''re a genious Mr.Mystery!


Anything to help the community.

Dampe64, take a look at ->
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Hooks/UsingHooks.asp




If you want to disable the keyboard AND mouse, use the API "BlockInput" with a parameter of TRUE if the target OS is Win98 or higher.

However be careful because there will be no way to interact with/break the running program until BlockInput(FALSE); is called! The only way out of it if the input is blocked is a reboot of the machine!
I was trying the LowLevelKeyboardProc() function above but it gives me several errors. I am trying to compile on a XP Pro machine. Any suggestions?
quote:Original post by darkchrono4
I was trying the LowLevelKeyboardProc() function above but it gives me several errors. I am trying to compile on a XP Pro machine. Any suggestions?


Post the errors

Actually I put the code into a dll and didn''t have a problem.

This topic is closed to new replies.

Advertisement