fix alt+tab behavior and improve keys mapping on windows

This commit is contained in:
2019-03-06 12:21:14 +01:00
parent 4141ba0ce6
commit b484e495ff
2 changed files with 49 additions and 32 deletions

View File

@@ -28,6 +28,7 @@ bool keys[256];
std::mutex gl_mutex;
std::mutex async_mutex;
std::thread::id gl_thread;
std::map<kKey, int> vkey_map;
std::thread hmd_renderer;
std::thread renderer;
@@ -406,6 +407,29 @@ static void SetupExceptionHandler()
}, 0);
}
// create a reverse map from kKey to VK_XXX
void init_vk_map()
{
for (int k = 1; k < 256; k++) // ignore kKey::Unknown = 0
{
for (int vk = 0; vk < 256; vk++)
{
if (k == (int)convert_key(k))
{
if (vkey_map.find((kKey)k) == vkey_map.end())
{
vkey_map.insert({ (kKey)k, vk });
}
else
{
LOG("KEY MAP COLLISION %d and %d maps to",
(int)vk, (int)vkey_map[(kKey)k], (int)k);
}
}
}
}
}
int main(int argc, char** argv)
{
WNDCLASS wc;
@@ -416,6 +440,7 @@ int main(int argc, char** argv)
if (argc == 1)
App::I.initLog();
init_vk_map();
/*
if (!App::I.check_license())
{
@@ -863,31 +888,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
tasklist.emplace_back([=] {
int active = GET_WM_ACTIVATE_STATE(wp, lp);
WacomTablet::I.set_focus(active);
for (int k = 0; k < 256; k++)
static BYTE keys[256];
if (GetKeyboardState(keys))
{
if (App::I.keys[k])
bool alt = keys[VK_TAB] & 0x80;
for (auto k : vkey_map)
{
for (int i = 0; i < 256; i++)
{
if ((int)convert_key(i) == k)
{
bool down = GetKeyState(i) & 0x8000;
if (!down)
App::I.key_up((kKey)k);
}
}
}
else
{
for (int i = 0; i < 256; i++)
{
if ((int)convert_key(i) == k)
{
bool down = GetKeyState(i) & 0x8000;
if (down)
App::I.key_down((kKey)k);
}
}
// ignore alt + tab
if (alt && k.first == kKey::KeyAlt)
continue;
bool down = keys[k.second] & 0x80;
if (App::I.keys[(int)k.first] && !down)
App::I.key_up(k.first);
else if(!App::I.keys[(int)k.first] && down)
App::I.key_down(k.first);
}
}
});
@@ -913,9 +927,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
}
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
if ((lp >> 30 & 1) == 0) // ignore repeated
if ((lp >> 30 & 1) == 0 && // ignore repeated
!(wp == VK_TAB && App::I.keys[(int)kKey::KeyAlt])) // ignore alt+tab
{
std::lock_guard<std::mutex> lock(task_mutex);
tasklist.emplace_back([wp] {
App::I.key_down(convert_key((int)wp));
@@ -924,6 +938,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
break;
case WM_SYSKEYUP:
case WM_KEYUP:
if (!(wp == VK_TAB && App::I.keys[(int)kKey::KeyAlt])) // ignore alt+tab
{
std::lock_guard<std::mutex> lock(task_mutex);
tasklist.emplace_back([wp] {