diff --git a/Inc/Keyboard.h b/Inc/Keyboard.h index 5d51ad22..cfdb6aac 100644 --- a/Inc/Keyboard.h +++ b/Inc/Keyboard.h @@ -452,6 +452,9 @@ namespace DirectX // Reset the keyboard state void __cdecl Reset(); + // Feature detection + bool __cdecl IsConnected() const; + #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) && defined(WM_USER) static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam); #endif diff --git a/Inc/Mouse.h b/Inc/Mouse.h index 5f805603..504d047b 100644 --- a/Inc/Mouse.h +++ b/Inc/Mouse.h @@ -90,7 +90,10 @@ namespace DirectX // Sets mouse mode (defaults to absolute) void __cdecl SetMode(Mode mode); - + + // Feature detection + bool __cdecl IsConnected() const; + #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) && defined(WM_USER) void __cdecl SetWindow(HWND window); static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam); diff --git a/Src/Keyboard.cpp b/Src/Keyboard.cpp index b5e20bbe..2342c733 100644 --- a/Src/Keyboard.cpp +++ b/Src/Keyboard.cpp @@ -62,6 +62,8 @@ namespace // } // +#include + class Keyboard::Impl { public: @@ -98,6 +100,26 @@ class Keyboard::Impl memset( &mState, 0, sizeof(State) ); } + bool IsConnected() const + { + using namespace Microsoft::WRL; + using namespace Microsoft::WRL::Wrappers; + using namespace ABI::Windows::Devices::Input; + using namespace ABI::Windows::Foundation; + + ComPtr caps; + HRESULT hr = RoActivateInstance(HStringReference(RuntimeClass_Windows_Devices_Input_KeyboardCapabilities).Get(), &caps); + ThrowIfFailed(hr); + + INT32 value; + if (SUCCEEDED(caps->get_KeyboardPresent(&value))) + { + return value != 0; + } + + return false; + } + void SetWindow(ABI::Windows::UI::Core::ICoreWindow* window) { using namespace Microsoft::WRL; @@ -294,6 +316,11 @@ class Keyboard::Impl { } + bool IsConnected() const + { + return false; + } + Keyboard* mOwner; static Keyboard::Impl* s_keyboard; @@ -361,6 +388,11 @@ class Keyboard::Impl memset( &mState, 0, sizeof(State) ); } + bool IsConnected() const + { + return true; + } + State mState; Keyboard* mOwner; @@ -479,6 +511,11 @@ void Keyboard::Reset() } +bool Keyboard::IsConnected() const +{ + return pImpl->IsConnected(); +} + Keyboard& Keyboard::Get() { if ( !Impl::s_keyboard || !Impl::s_keyboard->mOwner ) diff --git a/Src/Mouse.cpp b/Src/Mouse.cpp index e400bf99..e5cac7a1 100644 --- a/Src/Mouse.cpp +++ b/Src/Mouse.cpp @@ -172,6 +172,26 @@ class Mouse::Impl } } + bool IsConnected() const + { + using namespace Microsoft::WRL; + using namespace Microsoft::WRL::Wrappers; + using namespace ABI::Windows::Devices::Input; + using namespace ABI::Windows::Foundation; + + ComPtr caps; + HRESULT hr = RoActivateInstance(HStringReference(RuntimeClass_Windows_Devices_Input_MouseCapabilities).Get(), &caps); + ThrowIfFailed(hr); + + INT32 value; + if (SUCCEEDED(caps->get_MousePresent(&value))) + { + return value != 0; + } + + return false; + } + void SetWindow(ABI::Windows::UI::Core::ICoreWindow* window) { using namespace Microsoft::WRL; @@ -469,6 +489,11 @@ class Mouse::Impl UNREFERENCED_PARAMETER(mode); } + bool IsConnected() const + { + return false; + } + Mouse* mOwner; static Mouse::Impl* s_mouse; @@ -609,6 +634,11 @@ class Mouse::Impl } } + bool IsConnected() const + { + return GetSystemMetrics(SM_MOUSEPRESENT) != 0; + } + void SetWindow(HWND window) { if (mWindow == window) @@ -926,6 +956,12 @@ void Mouse::SetMode(Mode mode) } +bool Mouse::IsConnected() const +{ + return pImpl->IsConnected(); +} + + Mouse& Mouse::Get() { if ( !Impl::s_mouse || !Impl::s_mouse->mOwner )