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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blocking Keyboard and Mouse Input

Status
Not open for further replies.

wolfie78uk

Programmer
Jul 3, 2002
35
GB
I was trying to block all keyboard and mouse input whilst running my VB application but was unable to do so with the API functions in VB.

This may be a horribly long winded way to do it (and I leave myself open to the mockery of the experienced programmers) but it works.

1)Open up Visual C++ and create a new Empty Win32DLL Project called BlockInput.
2)Add a C++ file (with a .cpp extension) to your project - call it "BlockInput.cpp"

In the .cpp file write :

void _stdcall BlockInput(bool State)
{

if (State == True)

BlockInput(True);

else

BlockInput(False);

};

3) Add a define file to your project(select a text file and call it "BlockInput.def")

In the .def file write :

LIBRARY BlockInput

EXPORTS
BlockInput @1

4) Build the project and BlockInput.DLL will be created probably in the MSVisualStudio/MyProjects/)

directory.

5) Copy the DLL into WINNT/System32.

6) In your VB Module decalre the following :

Declare Sub BlockInput Lib "BlockInput.dll" (ByVal State As Boolean)

7) Now you can use it :

call BlockInput(True) 'Blocks Input
call BlockInput(False) 'Allows input

I hope somebody finds this useful.

Oh, and if anybody wants the DLL let me know.
 
Thats great, how would i be able to add in extra control, like locking just the keyboard or just the mouse?
and how could i trap the ctrl+alt+del event?
 
I think the function that you created is just the same as the API BlockInput.

What is the difference between your function and the API Block Input if there is any?

 
It is, but i am trying to figure out how exactly it is doing what it is doing. How does the code work. I am not very strong with C++ so am not sure about the functionality of this code. I know and can understand the vb side of it though. I am just wondering if there is an additional way to control the mouse and/or keyboard seperate from each other.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top