Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions include/vsg/platform/win32/Win32_Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ namespace vsgWin32
bool getKeySymbol(WPARAM wParam, LPARAM lParam, vsg::KeySymbol& keySymbol, vsg::KeySymbol& modifiedKeySymbol, vsg::KeyModifier& keyModifier)
{
uint16_t modifierMask = 0;
uint32_t virtualKey = ::MapVirtualKeyEx((lParam >> 16) & 0xff, MAPVK_VSC_TO_VK_EX, ::GetKeyboardLayout(0));

// see https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#keystroke-message-flags
WORD vkCode = LOWORD(wParam); // virtual-key code
WORD keyFlags = HIWORD(lParam);
WORD scanCode = LOBYTE(keyFlags); // scan code
BOOL isExtendedKey = (keyFlags & KF_EXTENDED) == KF_EXTENDED; // extended-key flag, 1 if scancode has 0xE0 prefix

if (isExtendedKey)
scanCode = MAKEWORD(scanCode, 0xE0);

uint32_t virtualKey = ::MapVirtualKeyEx(scanCode, MAPVK_VSC_TO_VK_EX, ::GetKeyboardLayout(0));
auto itr = _vk2vsg.find(virtualKey);

if (itr == _vk2vsg.end())
Expand Down Expand Up @@ -80,7 +90,7 @@ namespace vsgWin32
break;

default:
virtualKey = static_cast<int>(wParam);
virtualKey = static_cast<uint32_t>(wParam);
break;
}

Expand All @@ -102,7 +112,7 @@ namespace vsgWin32

// The actual keystroke is what we get after the ::ToAscii call
char asciiKey[2];
int32_t numChars = ::ToAscii(static_cast<UINT>(wParam), (lParam >> 16) & 0xff, keyState, reinterpret_cast<WORD*>(asciiKey), 0);
int32_t numChars = ::ToAsciiEx(static_cast<UINT>(wParam), scanCode, keyState, reinterpret_cast<WORD*>(asciiKey), 0, ::GetKeyboardLayout(0));
if (numChars == 1)
{
// it is indeed an ascii character. 0-127
Expand Down
44 changes: 22 additions & 22 deletions src/vsg/platform/win32/Win32_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ KeyboardMap::KeyboardMap()
{VK_RETURN , KEY_Return},
{VK_SHIFT , KEY_Undefined},
{VK_CONTROL , KEY_Undefined},
{VK_MENU , KEY_Undefined},
{VK_MENU , KEY_Alt_L},
Copy link
Collaborator

@robertosfield robertosfield Jul 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't this map to KEY_Menu?

Copy link
Contributor Author

@lufriem lufriem Jul 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VK_MENU on Windows is the (left) 'Alt' key. KEY_Menu is (according to KeyEvent.h) supposed to be "VK_APPS, the context-menu key" (I elaborated on this a bit more in the issue discussion)

{VK_PAUSE , KEY_Pause},
{VK_CAPITAL , KEY_Undefined},
{VK_KANA , KEY_Undefined},
Expand All @@ -149,32 +149,32 @@ KeyboardMap::KeyboardMap()
{VK_RIGHT , KEY_Right },
{VK_DOWN , KEY_Down },
{VK_SELECT , KEY_Select},
{VK_PRINT , KEY_Print},
{VK_SNAPSHOT , KEY_Print},
Copy link
Collaborator

@robertosfield robertosfield Jul 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If VK_PRINT shouldn't map to KEY_Print would should VK_SNAPSHOT?

What does VK_PRINT and KEY_Print meaning and are you assuming?

As a general reference I used X11 conventions that the OSG adopted decades ago, so whole not 1:1 compatible the VSG KEY_ enum is broadly like the OSG's.

Copy link
Contributor Author

@lufriem lufriem Jul 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that's a good/valid question..

  • I assumed KEY_Print would be the 'Print screen' hotkey/functionality.
  • while the MSDN lists the VK_PRINT constant all it says is that it is the 'PRINT key' (I searched around a bit but I could only find this stackoverflow discussion where it's stated that VK_PRINT is basically a nowadays unused remnant from 83/84 key IBM XT/AT machines). However looking at they keyboard in front of me, pressing the 'PrtSc' key I could see that the VK_SNAPSHOT event was created by Windows :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried under Linux and pressing "Press Screen" is mapping to VK_PRINT, so if Windows generates VK_SNAPSHOT for this key then that would be correct mapping.

{VK_EXECUTE , KEY_Execute},
{VK_SNAPSHOT , KEY_Undefined},
{VK_INSERT , KEY_Insert},
{VK_DELETE , KEY_Delete},
{VK_HELP , KEY_Help},
{VK_LWIN , KEY_Super_L},
{VK_RWIN , KEY_Super_R},
{VK_APPS , KEY_Undefined},
{VK_APPS , KEY_Menu},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um... VK_Menu isn't a menu but VK_APPS is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see this comment above

{VK_SLEEP , KEY_Undefined},
{VK_NUMPAD0 , KEY_Undefined},
{VK_NUMPAD1 , KEY_Undefined},
{VK_NUMPAD2 , KEY_Undefined},
{VK_NUMPAD3 , KEY_Undefined},
{VK_NUMPAD4 , KEY_Undefined},
{VK_NUMPAD5 , KEY_Undefined},
{VK_NUMPAD6 , KEY_Undefined},
{VK_NUMPAD7 , KEY_Undefined},
{VK_NUMPAD8 , KEY_Undefined},
{VK_NUMPAD9 , KEY_Undefined},
{VK_MULTIPLY , KEY_Undefined},
{VK_ADD , KEY_Undefined},
{VK_SEPARATOR , KEY_Undefined},
{VK_SUBTRACT , KEY_Undefined},
{VK_DECIMAL , KEY_Undefined},
{VK_DIVIDE , KEY_Undefined},
{VK_NUMPAD0 , KEY_KP_0},
{VK_NUMPAD1 , KEY_KP_1},
{VK_NUMPAD2 , KEY_KP_2},
{VK_NUMPAD3 , KEY_KP_3},
{VK_NUMPAD4 , KEY_KP_4},
{VK_NUMPAD5 , KEY_KP_5},
{VK_NUMPAD6 , KEY_KP_6},
{VK_NUMPAD7 , KEY_KP_7},
{VK_NUMPAD8 , KEY_KP_8},
{VK_NUMPAD9 , KEY_KP_9},
{VK_MULTIPLY , KEY_KP_Multiply},
{VK_ADD , KEY_KP_Add},
{VK_SEPARATOR , KEY_KP_Separator},
{VK_SUBTRACT , KEY_KP_Subtract},
{VK_DECIMAL , KEY_KP_Decimal},
{VK_DIVIDE , KEY_KP_Divide},
{VK_F1 , KEY_F1},
{VK_F2 , KEY_F2},
{VK_F3 , KEY_F3},
Expand Down Expand Up @@ -208,13 +208,13 @@ KeyboardMap::KeyboardMap()
{VK_NAVIGATION_ACCEPT , KEY_Undefined}, // reserved
{VK_NAVIGATION_CANCEL , KEY_Undefined}, // reserved
{VK_NUMLOCK , KEY_Undefined},
{VK_SCROLL , KEY_Undefined},
{VK_SCROLL , KEY_Scroll_Lock},
{VK_LSHIFT , KEY_Shift_L},
{VK_RSHIFT , KEY_Shift_R},
{VK_LCONTROL , KEY_Control_L},
{VK_RCONTROL , KEY_Control_R},
{VK_LMENU , KEY_Menu},
{VK_RMENU , KEY_Menu},
{VK_LMENU , KEY_Alt_L},
{VK_RMENU , KEY_Alt_R},
{VK_BROWSER_BACK , KEY_Undefined},
{VK_BROWSER_FORWARD , KEY_Undefined},
{VK_BROWSER_REFRESH , KEY_Undefined},
Expand Down