Touch, mouse and keyboard Dispatcher PointerPosition Pointer Events GetAsyncKeyState Key Events CoreWindow Activate, Close Closed Event Event dispatcher PointerPoint unified touch & mouse input Keyboard input Window management and events Bounds SizeChanged Event Window.

Download Report

Transcript Touch, mouse and keyboard Dispatcher PointerPosition Pointer Events GetAsyncKeyState Key Events CoreWindow Activate, Close Closed Event Event dispatcher PointerPoint unified touch & mouse input Keyboard input Window management and events Bounds SizeChanged Event Window.

Touch, mouse and
keyboard
Dispatcher
PointerPosition
Pointer Events
GetAsyncKeyState
Key Events
CoreWindow
Activate, Close
Closed Event
Event dispatcher
PointerPoint unified touch & mouse input
Keyboard input
Window management and events
Bounds
SizeChanged Event Window size query and notification
PointerCursor
Release/Set
PointerCapture
Cursor icon changes
Pointer capture
using namespace Windows::UI::Core;
void View::Initialize(_In_ CoreWindow^ window, _In_ CoreApplicationView^ applicationView)
{
// ...
// Add event handlers for pointer events
new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &View::OnPointerPressed);
m_window->PointerReleased +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &View::OnPointerReleased);
m_window->PointerMoved +=
ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &View::OnPointerMoved);
}
inline XMFLOAT2 PointToTouch(Windows::Foundation::Point point, Windows::Foundation::Size size)
{
float touchRadius = min(size.Width, size.Height);
float dx = (point.X - (size.Width / 2.0f)) / touchRadius;
float dy = ((size.Height / 2.0f) - point.Y) / touchRadius;
return XMFLOAT2(dx, dy);
}
// m_Touches is map data structure of touch regions used for screen tilt
// m_PointQueue is a queue data structure of touch points used for UI hit-testing
void View::OnPointerPressed(_In_ CoreWindow^ sender, _In_ PointerEventArgs^ args)
{
}
void View::OnPointerReleased(_In_ CoreWindow^ sender, _In_ PointerEventArgs^ args)
{
}
void View::OnPointerMoved(In_ CoreWindow^ sender,_In_ PointerEventArgs^ args)
{
if (m_Touches.find(id) != m_Touches.end())
m_Touches[
] = PointToTouch(point, m_renderTargetSize);
}
using namespace
using namespace
// Collect input from left/right arrow keys, left/right mouse buttons
bool leftKeyDown = (bool)(m_window->
GetAsyncKeyState(VirtualKey::Left) & CoreVirtualKeyStates::Down);
bool rightKeyDown = (bool)(m_window->
GetAsyncKeyState(VirtualKey::Right) & CoreVirtualKeyStates::Down);
// Mouse input too!
bool leftButtonDown = (bool)(m_window->
GetAsyncKeyState(VirtualKey::LeftButton) & CoreVirtualKeyStates::Down);
bool rightButtonDown = (bool)(m_window->
GetAsyncKeyState(VirtualKey::RightButton) & CoreVirtualKeyStates::Down);
Sensors
𝒖
x, y, z α
Z+
α
Y+
X+
Z+
Y+
X+
Y+
Y+
Z-
ZX+
X+
using namespace
using namespace
if ( m_orientationsensor )
{
// Setting ReportInterval requires event handler to be connected
m_orientationsensor->ReadingChanged +=ref new
TypedEventHandler<OrientationSensor^,
OrientationSensorReadingChangedEventArgs^>(this,
&InputHelper::OrientationReadingChanged);
m_orientationsensor->ReportInterval =
m_orientationsensor->MinimumReportInterval;
// Get current reading from sensor
// Transform quaternion from device orientation space to world space
// Orientation space is Z-up, right-handed coordinate system
// World space is Y-up, left-handed coordinate system
// Create a rotation matrix from the quaternion
// This matrix can be used to rotate an object inside the scene to match
// the rotation of the device
Game controllers
if (!m_isControllerConnected)
{
uint64 currentTime = ::GetTickCount64();
if (currentTime - m_lastEnumTime < XINPUT_ENUM_TIMEOUT_MS) return;
m_lastEnumTime = currentTime;
// Check for controller connection by trying to get the capabilities
uint32 capsResult = XInputGetCapabilities(0, XINPUT_FLAG_GAMEPAD, &m_xinputCaps);
if (capsResult != ERROR_SUCCESS) return;
// Device is connected
m_isControllerConnected = true;
}
uint32 stateResult = XInputGetState(0, &m_xinputState);
if (stateResult != ERROR_SUCCESS)
{
// Device is no longer connected
m_isControllerConnected = false;
m_lastEnumTime = ::GetTickCount64();
}
if ( m_xinputState.Gamepad.wButtons & XINPUT_GAMEPAD_A )
{
m_aButtonWasPressed = true;
}
else if ( m_aButtonWasPressed )
{
// Trigger once, only on button release
m_aButtonWasPressed = false;
TriggerSoundEffect();
}
if (abs(thumbLeftX) < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
thumbLeftX = 0;
SHORT thumbLeftY = inputState.Gamepad.sThumbLY;
if (abs(thumbLeftY) < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
thumbLeftY = 0;
combinedTiltX += (float)thumbLeftX / 32768.0f;
combinedTiltY += (float)thumbLeftY / 32768.0f;
terminology guide
Controller graphics
Button graphics
Synthesis
Form factor
Touch
Keyboard &
Mouse
Sensors
Game
Controllers
Tablet
Primary
Optional
Secondary
Optional
Desktop PC
Optional
Primary
N/A
Secondary
Laptop
Secondary
Primary
N/A
Optional
Convertible
Primary
Primary
Secondary
Optional
All-in-One PC
Primary
Secondary
N/A
Optional
Driver
Driver
Driver
Event
Queue
Frame 1
Dispatch
Event
Handlers
Input
Request
Game
Render
Loop
Frame 2
Game
Render
Loop
Frame 2
Frame 1
Continuous vs. discrete data
Review
Developing the Metro Style Marble Maze game with DirectX
Working with Input & Controls in your DirectX game
Direct3D 11.1 Features
XInput Documentation
http://forums.dev.windows.com
http://forums.dev.windows.com
http://bldw.in/SessionFeedback
Microsoft UI Automation
Text Control Pattern
attribute
Sensor
Data
filtered?
Accelerometer
No
Gyrometer
No
Compass
Yes
Inclinometer
Yes
Orientation
Yes
Touch support
Component
Details
Certified Windows 8 Touch solution 5 point touch minimum
Camera
Front and/or Back Camera
Required Sensors Magnetometer (compass)
Accelerometer
Gyroscope
GPS
Ambient Light sensor
Hardware buttons Windows Key Button
ACPI Power button
USB
Rotation lock
Volume + and 1 exposed USB 2.0 port
Minimum resolution 720p
3 Axes, data rates >= 50Hz
>=50Hz
1-30k lux, 5-60K dynamic range
Controller and port required