Archived

This topic is now archived and is closed to further replies.

dampe64

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

Recommended Posts

If you mean physically off as in no power, I don''t think you can do that. If you want to disable the input of keys you could write a keyhook to block everything, but it can get kind of ugly.

Share this post


Link to post
Share on other sites
quote:
Original post by dampe64
could anyone give me the source for that


That''s not the kind of things you should do with cut-and-paste programming, and I doubt people keep that kind of things conveniently at hand to post in here.

You ought to start with the hook documentation in MSDN :

"hook - A callback function that handles I/O port and board memory accesses."

MSDN Library
-> User Interface Design and Development
-> Window Management
-> Windows User Interface
-> Windowing->Hooks

You probably want ''KeyboardProc'' or ''LowLevelKeyboardProc''.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
thank you i checked that out but i am still somewhat confused as to how to implement it (i know C and C++ but my Win32 API is lacking as there are so many functions).

any help or source would be appreciated

thanks

[edited by - dampe64 on October 6, 2003 10:45:25 PM]

Share this post


Link to post
Share on other sites
I did this a while back...

I discovered that the keyboard generates an INT 9 every time a key is pushed or released. You COULD hook this hardware hardware interrupt- much like I did...

This approach requires developing in kernel mode (writing a device driver) and you''ll need the Windows DDK (Driver development Kit) I''ll paste the most important parts of code you''re going to need - It was from a past project that I did a lot of research on- so you''re EXTREMELY lucky as Fruny said, to find anything like this -as it is all undocumented.


#define NT_KEYBOARD_INT 9

//Every time an event happens on the keyboard-this
//function gets called... if you want to deny ALL keyboard
//presses, leave the last line commented out- like I have.
//Otherwise, uncomment it.

__declspec(naked) MyKeyboardInterrupt()
{
__asm{
pushad
pushfd
push fs
mov bx,0x30
mov fs,bx
push ds
push es

pop es
pop ds
pop fs
popfd
popad

//jmp KiRealKeyboardISR_Ptr;
}
}
int HookKeyboardInterrupt()
{
IDTINFO idt_info;
IDTENTRY* idt_entries;
IDTENTRY* int9_entry;
__asm{
sidt idt_info;
}

idt_entries = (IDTENTRY*) MAKELONG(idt_info.LowIDTbase,idt_info.HiIDTbase);

KiRealKeyboardISR_Ptr = MAKELONG(idt_entries[NT_KEYBOARD_INT].LowOffset,idt_entries[NT_KEYBOARD_INT].HiOffset);

int9_entry = &(idt_entries[NT_KEYBOARD_INT]);

__asm{
cli;
lea eax,MyKeyboardInterrupt;
mov ebx, int9_entry;
mov [ebx],ax;
shr eax,16
mov [ebx+6],ax;

lidt idt_info;
sti;
}
return 0;
}

[/CODE]

Just call HookKeyboardInterrupt(); From DriverEntry().

Raloth is right- if the keyboard is physically connected to the computer- you can''t programmatically deny electric current to flow - not as far as I know.

The much easier approach is to Inject a DLL into all running processes and hook the GetMessage() and DispatchMessage() functions in Kernel32.dll- setting any WM_CHAR messages to WM_NULL. You can also use the unflexible SetWindowsHookEx() to do this. The problem with this approach is that you''ll have difficulties tracing down any registered Hotkey events and the sad fact of the matter is- you''ll NEVER get ALL the keyboard messages... I''d stick with the garenteed driver approach.

I hope this helps and I HOPE this isn''t for a no good reason... mate...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
OK how abot a real and useful question.
how can you disable alt+tab in windows 98 ?
in XP you can do registerhotkey() but not for 98. discuss.

Share this post


Link to post
Share on other sites
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);
}




Share this post


Link to post
Share on other sites
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




Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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!

Share this post


Link to post
Share on other sites