Okay Here it Is
First, you must download ht Windows SDK (it has the Direct X SDK included) You will also want to download a redirstrabutable Direct X as you will your application will require it.
Second here are the Import statements:
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Then you must declare your variables:
Dim keyboard As DirectInput.Device = Nothing
Dim mouse As DirectInput.Device = Nothing
To Get the Keyboard and Mouse use this:
keyboard.SetCooperativeLevel(
this,
DirectInput.CooperativeLevelFlags.Background | DirectInput.CooperativeLevelFlags.Exclusive );
keyboard = new DirectInput.Device( DirectInput.SystemGuid.Keyboard );
keyboard.Acquire();
mouse = new DirectInput.Device( DirectInput.SystemGuid.Mouse );
mouse.SetCooperativeLevel(
this,
DirectInput.CooperativeLevelFlags.Background | DirectInput.CooperativeLevelFlags.Exclusive );
mouse.SetDataFormat( DirectInput.DeviceDataFormat.Mouse );
mouse.Acquire();
Note: This only gives exclusive access of the Keyboard and Mouse to your Program.
Your program can still get keyboard and mouse inputs (by polling) if you write the extra code.
Microsoft say over and over again on their website, "For security reasons, do not set the CooperativeLevelFlags to Exclusive"(on the keyboard and mouse). You have been warned!!!
Your program will have to handle getting rid of the restriction.
I thought of writing a small app that takes the keyboard and mouse exclusively. To start the restriction, start the app. Then to terminate the restriction, you will have to find some way to terminate the program properly, through the
Application.Close()
method. I have some Ideas, but I am not going to try to explain it.
I can't find a unacquire snippet, so I think unacquire is called on App Exit.
This code has been converted to VB from C# with the help of
http://www.developerfusion.com[
^]
If it does not work, I can write the small app in C# for you.