Archived

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 5215 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites
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 on other sites
could anyone give me the source for that

...

click

Share on other sites
Sounds like mischief...

-DD

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.

"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 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 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 on other sites
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 on other sites
quote:

how can you disable alt+tab in windows 98 ?

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

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 on other sites
You''re a genious Mr.Mystery!

Share on other sites
Under XP you can call RegisterHotKey() but I''m not sure about other windows versions..

Share on other sites
could you show me the code o call the LowLevelKeyProc with SetWindowsHookEx.

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 on other sites
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 on other sites
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?

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

Share on other sites
Actually I put the code into a dll and didn''t have a problem.