Game Development Reference
In-Depth Information
Keyboard input
We now have touch and mouse input, but many players also use desktop or laptop
machines where playing with a mouse isn't the best experience. Thankfully they all
have a keyboard, which will let us add some simple controls to mimic the touch con-
trols that we currently have.
Just like the pointer system, keyboard events are raised by the CoreWindow object
that we have in the GameApplication class. To begin, create some event handlers
like you did for the OnPointerReleased handler, but use the KeyEventArgs in-
stead of PointerEventArgs .
Add the following code in the GameApplication.h file:
void OnKeyDown(Windows::UI::Core::CoreWindow^
sender, Windows::UI::Core::KeyEventArgs^ args);
void OnKeyUp(Windows::UI::Core::CoreWindow^
sender, Windows::UI::Core::KeyEventArgs^ args);
Now add the code that follows in the GameApplication.cpp file:
void
GameApplication::OnKeyDown(Windows::UI::Core::CoreWindow^
sender, Windows::UI::Core::KeyEventArgs^ args)
{
m_renderer->KeyDown(args->VirtualKey);
}
void
GameApplication::OnKeyUp(Windows::UI::Core::CoreWindow^
sender, Windows::UI::Core::KeyEventArgs^ args)
{
m_renderer->KeyUp(args->VirtualKey);
}
Search WWH ::




Custom Search