Managing Device References in DirectInput for Creating a Virtual Keyboard
180 likes | 311 Vues
This guide outlines how to manage ambiguous references when working with the DirectInput API in Microsoft DirectX, particularly for distinguishing between different device types. We explore creating a virtual keyboard by declaring a DirectInput device and initializing it. The document details two methods for gathering user input: polling and event notification, with a focus on the polling method for this implementation. It also explains how to retrieve keyboard state information to check specific key presses and respond accordingly, using the function GetCurrentKeyboardState().
Managing Device References in DirectInput for Creating a Virtual Keyboard
E N D
Presentation Transcript
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 • ...........