[gtk-vnc] win32: translate virtual-key code to scancode via MapVirtualKey



commit 483f801cf53fb455a71141eec648ca3fc71f4eb0
Author: Daniel P. Berrange <berrange redhat com>
Date:   Fri Feb 6 13:43:37 2015 +0000

    win32: translate virtual-key code to scancode via MapVirtualKey
    
    Local client keyboard layout shouldn't affect hardware scancode sent
    to guest, so that guest keyboard layout configuration can map it
    properly.
    
    Unfortunately, the Win32 GdkEventKey.hardware_keycode isn't a hardware
    scancode, but the Windows virtual-key code. We could modify Gdk to
    return the scancode (available in MSG.lParam or via global hook), but
    that would mean some Gdk breakage, or some unnecessary complexity.
    Instead, we can rely on MapVirtualKey(), which translates the
    vitual-key code into a scan code using current keyboard layout.
    
    This code is imported from SPICE-GTK

 src/vncdisplay.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/src/vncdisplay.c b/src/vncdisplay.c
index 5ac9492..d8afba2 100644
--- a/src/vncdisplay.c
+++ b/src/vncdisplay.c
@@ -43,6 +43,9 @@
 #ifdef G_OS_WIN32
 #include <windows.h>
 #include <gdk/gdkwin32.h>
+#ifndef MAPVK_VK_TO_VSC /* may be undefined in older mingw-headers */
+#define MAPVK_VK_TO_VSC 0
+#endif
 #endif
 
 #define VNC_DISPLAY_GET_PRIVATE(obj)                                    \
@@ -993,6 +996,11 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key)
             guint16 scancode = vnc_display_keymap_gdk2rfb(priv->keycode_map,
                                                           priv->keycode_maplen,
                                                           key->hardware_keycode);
+#ifdef G_OS_WIN32
+            /* MapVirtualKey doesn't return scancode with needed higher byte */
+            scancode = MapVirtualKey(key->hardware_keycode, MAPVK_VK_TO_VSC) |
+                (scancode & 0xff00);
+#endif
             /*
              * ..send the key release event we're dealing with
              *
@@ -1016,6 +1024,11 @@ static gboolean key_event(GtkWidget *widget, GdkEventKey *key)
                 guint16 scancode = vnc_display_keymap_gdk2rfb(priv->keycode_map,
                                                               priv->keycode_maplen,
                                                               key->hardware_keycode);
+#ifdef G_OS_WIN32
+                /* MapVirtualKey doesn't return scancode with needed higher byte */
+                scancode = MapVirtualKey(key->hardware_keycode, MAPVK_VK_TO_VSC) |
+                    (scancode & 0xff00);
+#endif
                 priv->down_keyval[i] = keyval;
                 priv->down_scancode[i] = key->hardware_keycode;
                 /* Send the actual key event we're dealing with */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]