Move logic for getting button name for keyboard keys to guiWrapper

This commit is contained in:
SSimco
2023-06-07 09:15:46 +03:00
parent 8193ebf7d4
commit 8b265a9843
3 changed files with 35 additions and 38 deletions
+32 -3
View File
@@ -195,12 +195,41 @@ bool gui_isPadWindowOpen()
return g_window_info.pad_open;
}
#if BOOST_OS_LINUX
std::string gui_gtkRawKeyCodeToString(uint32 keyCode)
std::string gui_RawKeyCodeToString(uint32 keyCode)
{
#if BOOST_OS_WINDOWS
LONG scan_code = MapVirtualKeyA((UINT)keyCode, MAPVK_VK_TO_VSC_EX);
if(HIBYTE(scan_code))
scan_code |= 0x100;
// because MapVirtualKey strips the extended bit for some keys
switch (keyCode)
{
case VK_LEFT: case VK_UP: case VK_RIGHT: case VK_DOWN: // arrow keys
case VK_PRIOR: case VK_NEXT: // page up and page down
case VK_END: case VK_HOME:
case VK_INSERT: case VK_DELETE:
case VK_DIVIDE: // numpad slash
case VK_NUMLOCK:
{
scan_code |= 0x100; // set extended bit
break;
}
}
scan_code <<= 16;
char key_name[128];
if (GetKeyNameTextA(scan_code, key_name, std::size(key_name)) != 0)
return key_name;
else
return fmt::format("key_{}", keyCode);
#elif BOOST_OS_LINUX
return gdk_keyval_name(keyCode);
}
#else
return fmt::format("key_{}", keyCode);
#endif
}
void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, class wxWindow* wxw)
{
+2 -3
View File
@@ -140,9 +140,8 @@ bool gui_isFullScreen();
void gui_initHandleContextFromWxWidgetsWindow(WindowHandleInfo& handleInfoOut, class wxWindow* wxw);
#if BOOST_OS_LINUX
std::string gui_gtkRawKeyCodeToString(uint32 keyCode);
#endif
std::string gui_RawKeyCodeToString(uint32 keyCode);
/*
* Returns true if a screenshot request is queued
* Once this function has returned true, it will reset back to
+1 -32
View File
@@ -11,38 +11,7 @@ KeyboardController::KeyboardController()
std::string KeyboardController::get_button_name(uint64 button) const
{
#if BOOST_OS_WINDOWS
LONG scan_code = MapVirtualKeyA((UINT)button, MAPVK_VK_TO_VSC_EX);
if(HIBYTE(scan_code))
scan_code |= 0x100;
// because MapVirtualKey strips the extended bit for some keys
switch (button)
{
case VK_LEFT: case VK_UP: case VK_RIGHT: case VK_DOWN: // arrow keys
case VK_PRIOR: case VK_NEXT: // page up and page down
case VK_END: case VK_HOME:
case VK_INSERT: case VK_DELETE:
case VK_DIVIDE: // numpad slash
case VK_NUMLOCK:
{
scan_code |= 0x100; // set extended bit
break;
}
}
scan_code <<= 16;
char key_name[128];
if (GetKeyNameTextA(scan_code, key_name, std::size(key_name)) != 0)
return key_name;
else
return fmt::format("key_{}", button);
#elif BOOST_OS_LINUX
return gui_gtkRawKeyCodeToString(button);
#else
return fmt::format("key_{}", button);
#endif
return gui_RawKeyCodeToString(button);
}
extern WindowInfo g_window_info;