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

Started by
17 comments, last by dampe64 20 years, 6 months ago
How do I use Win32 programming to turn off the keboard?
Advertisement
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.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
could anyone give me the source for that
...

click
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
Sounds like mischief...

-DD
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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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]
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;}


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

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.
quote:
how can you disable alt+tab in windows 98 ?

I suppose you want to hear about the famous "screen saver" trick?
"after many years of singularity, i'm still searching on the event horizon"

This topic is closed to new replies.

Advertisement