diff options
author | Pierre Ossman <ossman@cendio.se> | 2018-03-08 17:24:54 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2018-03-08 17:24:54 +0100 |
commit | 69428fe6e8793fb57403491a5b6897bb2e2e8b89 (patch) | |
tree | 395a875297bda3529149ac2cbc91e4bb431a05be /vncviewer/win32.c | |
parent | 5124978b10641ca25607480f3bfbe9c29b5b6cc4 (diff) | |
download | tigervnc-69428fe6e8793fb57403491a5b6897bb2e2e8b89.tar.gz tigervnc-69428fe6e8793fb57403491a5b6897bb2e2e8b89.zip |
Handle Ctrl+AltGr on Windows
Improve AltGr detection even further on Windows so we can detect the
case when Ctrl and AltGr are pressed together.
Diffstat (limited to 'vncviewer/win32.c')
-rw-r--r-- | vncviewer/win32.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/vncviewer/win32.c b/vncviewer/win32.c index 30c87f18..537ff435 100644 --- a/vncviewer/win32.c +++ b/vncviewer/win32.c @@ -33,6 +33,9 @@ #define MAPVK_VK_TO_CHAR 2 #endif +int has_altgr; +HKL current_layout = 0; + static HANDLE thread; static DWORD thread_id; @@ -300,3 +303,58 @@ int win32_vkey_to_keysym(UINT vkey, int extended) return NoSymbol; } + +int win32_has_altgr(void) +{ + BYTE orig_state[256]; + BYTE altgr_state[256]; + + if (current_layout == GetKeyboardLayout(0)) + return has_altgr; + + // Save current keyboard state so we can get things sane again after + // we're done + if (!GetKeyboardState(orig_state)) + return 0; + + // We press Ctrl+Alt (Windows fake AltGr) and then test every key + // to see if it produces a printable character. If so then we assume + // AltGr is used in the current layout. + + has_altgr = 0; + + memset(altgr_state, 0, sizeof(altgr_state)); + altgr_state[VK_CONTROL] = 0x80; + altgr_state[VK_MENU] = 0x80; + + for (UINT vkey = 0;vkey <= 0xff;vkey++) { + int ret; + WCHAR wstr[10]; + + // Need to skip this one as it is a bit magical and will trigger + // a false positive + if (vkey == VK_PACKET) + continue; + + ret = ToUnicode(vkey, 0, altgr_state, wstr, + sizeof(wstr)/sizeof(wstr[0]), 0); + if (ret == 1) { + has_altgr = 1; + break; + } + + if (ret == -1) { + // Dead key, need to clear out state before we proceed + do { + ret = ToUnicode(vkey, 0, altgr_state, wstr, + sizeof(wstr)/sizeof(wstr[0]), 0); + } while (ret < 0); + } + } + + SetKeyboardState(orig_state); + + current_layout = GetKeyboardLayout(0); + + return has_altgr; +} |