• Advertisement


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

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

This topic is 5306 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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


[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.


//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()
push fs
mov bx,0x30
mov fs,bx
push ds
push es

pop es
pop ds
pop fs

//jmp KiRealKeyboardISR_Ptr;
int HookKeyboardInterrupt()
IDTINFO idt_info;
IDTENTRY* idt_entries;
IDTENTRY* int9_entry;
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]);

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

lidt idt_info;
return 0;


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

  • Advertisement