1 / 18

Creating a Virtual Keyboard Using Microsoft DirectX DirectInput

This guide provides step-by-step instructions for creating a virtual keyboard using Microsoft DirectX DirectInput. It explains how to distinguish between devices, initialize the keyboard, and implement polling to check for key presses. You'll learn how to set cooperative levels and acquire the keyboard state to detect user input. The tutorial covers key concepts such as device management, event handling, and the use of functions like `GetCurrentKeyboardState()` to retrieve keyboard status, ensuring you can effectively manage user interactions within your application.

semah
Télécharger la présentation

Creating a Virtual Keyboard Using Microsoft DirectX DirectInput

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DirectInput

  2. using Microsoft.DirectX.DirectInput;

  3. Error ambigious reference

  4. Teh keyboard is also a device • So we need so make them distinguishable

  5. We could distinguish beteween the two different types of devices writing out their full names Microsoft.DirectX.Direct3D.Device mydevice; Microsoft.DirectX.DirectInput.Devicemykeyboard;

  6. Or we could use alias • using DirectInput = Microsoft.DirectX.DirectInput; • using Direct3D = Microsoft.DirectX.Direct3D;

  7. 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;

  8. How to create a virtual keyboard First we need to declare a variable of the type DirectInput.Device DirectInput.Devicemykeyboard=null;

  9. How to create a virtual keyboard Then we need to create it /initialize it

  10. 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(); }

  11. So now we have a vritual keyboard • How can the program get information about • When/if a tangent is used by a user.

  12. There are two different ways 1) polling 2)event notifier

  13. There are two different ways 1) polling // the program aske the keyboard 2)event notifier// the keyboard informs the program by sending an event....

  14. We will use the first method • Polling. • In each lap the program askes the keyboard if there might be a tangent down or not?

  15. In order to ”ask” the keyboard we will use a function called • GetCurrentKeyboardState()

  16. 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

  17. 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]

  18. DirectInput.KeyboardStatekstate = mykeyboard.GetCurrentKeyboardState();if (kstate[DirectInput.Key.DownArrow]) • Change the y coordinate….…….. • else • ...........

More Related