180 likes | 299 Views
DirectInput. using Microsoft.DirectX.DirectInput ;. Error ambigious reference. Teh keyboard is also a device. So we need so make them distinguishable . We could distinguish beteween the two different types of devices writing out their full names.
E N D
Teh keyboard is also a device • So we need so make them distinguishable
We could distinguish beteween the two different types of devices writing out their full names Microsoft.DirectX.Direct3D.Device mydevice; Microsoft.DirectX.DirectInput.Devicemykeyboard;
Or we could use alias • using DirectInput = Microsoft.DirectX.DirectInput; • using Direct3D = Microsoft.DirectX.Direct3D;
We need to change all the graphic-card-type -devices we have in the code, as for example Device mindevice = null; to Direct3D.Device mindevice = null;
How to create a virtual keyboard First we need to declare a variable of the type DirectInput.Device DirectInput.Devicemykeyboard=null;
How to create a virtual keyboard Then we need to create it /initialize it
Best done in a function void intierartangentbordet() { mykeyboard=new DirectInput.Device (DirectInput.SystemGuid.Keyboard); mykeyboard.SetCooperativeLevel(this,DirectInput.CooperativeLevelFlags.Background|DirectInput.CooperativeLevelFlags.NonExclusive ); mykeyboard.Acquire(); }
So now we have a vritual keyboard • How can the program get information about • When/if a tangent is used by a user.
There are two different ways 1) polling 2)event notifier
There are two different ways 1) polling // the program aske the keyboard 2)event notifier// the keyboard informs the program by sending an event....
We will use the first method • Polling. • In each lap the program askes the keyboard if there might be a tangent down or not?
In order to ”ask” the keyboard we will use a function called • GetCurrentKeyboardState()
In order to ”ask” the keyboard we will use a function called • GetCurrentKeyboardState() • This function returns an array with information about the status of the keyboard
If we want to know if down arrow is hit • Then we check the array returned by the • GetCurrentKeyboardState • In this case called kstate • kstate[DXinput.Key.DownArrow]
DirectInput.KeyboardStatekstate = mykeyboard.GetCurrentKeyboardState();if (kstate[DirectInput.Key.DownArrow]) • Change the y coordinate….…….. • else • ...........