15 #define VK_USE_PLATFORM_WIN32_KHR
21 #include <vsg/app/Window.h>
22 #include <vsg/ui/KeyEvent.h>
23 #include <vsg/ui/PointerEvent.h>
28 #include <vulkan/vulkan_win32.h>
37 using VirtualKeyToKeySymbolMap = std::map<uint16_t, vsg::KeySymbol>;
39 bool getKeySymbol(WPARAM wParam, LPARAM lParam, vsg::KeySymbol& keySymbol, vsg::KeySymbol& modifiedKeySymbol, vsg::KeyModifier& keyModifier)
41 uint16_t modifierMask = 0;
42 uint32_t virtualKey = ::MapVirtualKeyEx((lParam >> 16) & 0xff, MAPVK_VSC_TO_VK_EX, ::GetKeyboardLayout(0));
43 auto itr = _vk2vsg.find(virtualKey);
45 if (itr == _vk2vsg.end())
53 keySymbol = itr->second;
57 if (virtualKey == 0 || !::GetKeyboardState(keyState))
69 modifierMask |= vsg::KeyModifier::MODKEY_Shift;
74 modifierMask |= vsg::KeyModifier::MODKEY_Control;
79 modifierMask |= vsg::KeyModifier::MODKEY_Alt;
83 virtualKey =
static_cast<int>(wParam);
88 if (keyState[VK_CAPITAL] & 0x01) modifierMask |= vsg::KeyModifier::MODKEY_CapsLock;
89 if (keyState[VK_NUMLOCK] & 0x01) modifierMask |= vsg::KeyModifier::MODKEY_NumLock;
93 if (keyState[VK_LSHIFT] & 0x80) modifierMask |= vsg::KeyModifier::MODKEY_Shift;
94 if (keyState[VK_LSHIFT] & 0x80) modifierMask |= vsg::KeyModifier::MODKEY_Shift;
95 if (keyState[VK_LCONTROL] & 0x80) modifierMask |= vsg::KeyModifier::MODKEY_Control;
96 if (keyState[VK_RCONTROL] & 0x80) modifierMask |= vsg::KeyModifier::MODKEY_Control;
97 if (keyState[VK_LMENU] & 0x80) modifierMask |= vsg::KeyModifier::MODKEY_Alt;
98 if (keyState[VK_LMENU] & 0x80) modifierMask |= vsg::KeyModifier::MODKEY_Alt;
101 keyModifier =
static_cast<vsg::KeyModifier
>(modifierMask);
105 int32_t numChars = ::ToAscii(
static_cast<UINT
>(wParam), (lParam >> 16) & 0xff, keyState,
reinterpret_cast<WORD*
>(asciiKey), 0);
109 modifiedKeySymbol =
static_cast<vsg::KeySymbol
>(asciiKey[0]);
114 modifiedKeySymbol = keySymbol;
121 VirtualKeyToKeySymbolMap _vk2vsg;
124 inline vsg::ButtonMask getButtonMask(WPARAM wParam)
126 auto mask = (wParam & MK_LBUTTON ? vsg::ButtonMask::BUTTON_MASK_1 : 0) | (wParam & MK_MBUTTON ? vsg::ButtonMask::BUTTON_MASK_2 : 0) | (wParam & MK_RBUTTON ? vsg::ButtonMask::BUTTON_MASK_3 : 0) |
127 (wParam & MK_XBUTTON1 ? vsg::ButtonMask::BUTTON_MASK_4 : 0) | (wParam & MK_XBUTTON2 ? vsg::ButtonMask::BUTTON_MASK_5 : 0);
128 return static_cast<vsg::ButtonMask
>(mask);
131 inline uint32_t getButtonDownEventDetail(UINT buttonMsg, WORD wParamHi)
135 case WM_LBUTTONDOWN:
return 1;
136 case WM_MBUTTONDOWN:
return 2;
137 case WM_RBUTTONDOWN:
return 3;
139 if (wParamHi == XBUTTON1)
141 else if (wParamHi == XBUTTON2)
150 inline uint32_t getButtonUpEventDetail(UINT buttonMsg, WORD wParamHi)
154 case WM_LBUTTONUP:
return 1;
155 case WM_MBUTTONUP:
return 2;
156 case WM_RBUTTONUP:
return 3;
158 if (wParamHi == XBUTTON1)
160 else if (wParamHi == XBUTTON2)
178 const char* instanceExtensionSurfaceName()
const override {
return VK_KHR_WIN32_SURFACE_EXTENSION_NAME; }
180 bool valid()
const override {
return _window; }
182 bool visible()
const override;
188 void resize()
override;
190 operator HWND()
const {
return _window; }
192 LRESULT handleWin32Messages(UINT msg, WPARAM wParam, LPARAM lParam);
197 void _initSurface()
override;
200 bool _windowMapped =
false;
Definition: Win32_Window.h:33
Win32_Window implements Win32 specific window creation, event handling and vulkan Surface setup.
Definition: Win32_Window.h:171
bool pollEvents(vsg::UIEvents &events) override
get the list of events since the last pollEvents() call by splicing bufferEvents with polled windowin...
void releaseWindow() override