Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling Keyboard? 1

Status
Not open for further replies.

Killianman

Programmer
Jul 8, 2001
3
0
0
IE
How do I disable the keyboard and mouse in my program?
Thanks.
 
Question:

If Keyboard and Mouse is disabled, How do you enable it again?

hnd
hasso55@yahoo.com

 
I don't think that it is possible to disable keyboard and mouse completely, because those devices are handled by OS, and I do not know a possiblity to lock the access to the OS.

hnd
hasso55@yahoo.com

 
There sure exists such function. John Fill
1c.bmp


ivfmd@mail.md
 

When I learnt Borland C++ for Win3.1/DOS, I programmed a lot about RS232 for fun. I wrote a program for DOS that can get command from antoher PC via RS232. If I disable the keyboard and mouse of one PC, I can still control it from another PC.

I think whether we can disable KB and mouse depends on the robustness of the OS. In DOS, definitely we can do it. In Win31, I still think we can do it. In W2K, I am not sure.
 
I've just found it. It is called SetWindowsHookEx. John Fill
1c.bmp


ivfmd@mail.md
 
How does it work? What version of C++ Builder is that in?
 
You should include windows.h. It is a Win32API fnction supported by all of them. In my opinion BCuilder5 has this ones kind of functions, and not only C++ builder5.
Try this code

#include<windows.h>
HHOOK x=0;
LRESULT CALLBACK KeyboardProc
(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
MessageBox(0,&quot;&quot;,&quot;&quot;,0);
return //LRESULT
CallNextHookEx(
x, // handle to current hook
code, // hook code passed to hook procedure
wParam, // value passed to hook procedure
lParam // value passed to hook procedure
);

}

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
x=SetWindowsHookEx(
WH_KEYBOARD, // hook type
KeyboardProc, // hook procedure
0, // handle to application instance
0// thread identifier
);
if(!x)
{
DWORD err=GetLastError();
}
BOOL UnhookWindowsHookEx(
(int)x
);
MSG msg;
while(GetMessage(&msg,0,0,0))
{
DispatchMessage(&msg);
}
return 0;
}
John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top