Adding keyboard and mouse controls with text output
One of the most important things that we require in a video game is a human interface to interact with. The most common interface devices are the keyboard and the mouse. Therefore, it is very important to understand how they work and how we can detect key presses and movements. It is equally important to know how to display specific text on the screen; this can be really useful for debugging and for HUD implementation.
Getting ready
For this recipe, you will need a Windows machine with a working copy of Visual Studio.
How to do it…
In this recipe, we will find out how easy it is to detect keyboard and mouse events:
Open Visual Studio.
Create a new C++ project.
Select a Win32 Windows application.
Add a source file called
Source.cpp
.Add the following lines of code to it:
#define WIN32_LEAN_AND_MEAN #include <windows.h> //Include all the Windows headers. #include <windowsx.h> //Include useful macros. #include <strstream> #include...