Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 107148)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp	(revision 107153)
@@ -108,4 +108,264 @@
 UIKeyboardHandler *UIKeyboardHandler::m_spKeyboardHandler = 0;
 #endif /* VBOX_WS_WIN */
+
+#define CODE_ARRAY_LENGTH 255
+
+LONG evcode_hid[CODE_ARRAY_LENGTH][2] = {
+    {0x7, 0x0}, //NULL
+    {0x7, 0x29}, //"Escape"
+    {0x7, 0x1e}, //"Digit1"
+    {0x7, 0x1f}, //"Digit2"
+    {0x7, 0x20}, //"Digit3"
+    {0x7, 0x21}, //"Digit4"
+    {0x7, 0x22}, //"Digit5"
+    {0x7, 0x23}, //"Digit6"
+    {0x7, 0x24}, //"Digit7"
+    {0x7, 0x25}, //"Digit8"
+    {0x7, 0x26}, //"Digit9"
+    {0x7, 0x27}, //"Digit0"
+    {0x7, 0x2d}, //"Minus"
+    {0x7, 0x2e}, //"Equal"
+    {0x7, 0x2a}, //"Backspace"
+    {0x7, 0x2b}, //"Tab"
+    {0x7, 0x14}, //"KeyQ"
+    {0x7, 0x1a}, //"KeyW"
+    {0x7, 0x8}, //"KeyE"
+    {0x7, 0x15}, //"KeyR"
+    {0x7, 0x17}, //"KeyT"
+    {0x7, 0x1c}, //"KeyY"
+    {0x7, 0x18}, //"KeyU"
+    {0x7, 0xc}, //"KeyI"
+    {0x7, 0x12}, //"KeyO"
+    {0x7, 0x13}, //"KeyP"
+    {0x7, 0x2f}, //"BracketLeft"
+    {0x7, 0x30}, //"BracketRight"
+    {0x7, 0x28}, //"Enter"
+    {0x7, 0xe0}, //"ControlLeft"
+    {0x7, 0x4}, //"KeyA"
+    {0x7, 0x16}, //"KeyS"
+    {0x7, 0x7}, //"KeyD"
+    {0x7, 0x9}, //"KeyF"
+    {0x7, 0xa}, //"KeyG"
+    {0x7, 0xb}, //"KeyH"
+    {0x7, 0xd}, //"KeyJ"
+    {0x7, 0xe}, //"KeyK"
+    {0x7, 0xf}, //"KeyL"
+    {0x7, 0x33}, //"Semicolon"
+    {0x7, 0x34}, //"Quote"
+    {0x7, 0x35}, //"Backquote"
+    {0x7, 0xe1}, //"ShiftLeft"
+    {0x7, 0x31}, //"Backslash"
+    {0x7, 0x1d}, //"KeyZ"
+    {0x7, 0x1b}, //"KeyX"
+    {0x7, 0x6}, //"KeyC"
+    {0x7, 0x19}, //"KeyV"
+    {0x7, 0x5}, //"KeyB"
+    {0x7, 0x11}, //"KeyN"
+    {0x7, 0x10}, //"KeyM"
+    {0x7, 0x36}, //"Comma"
+    {0x7, 0x37}, //"Period"
+    {0x7, 0x38}, //"Slash"
+    {0x7, 0xe5}, //"ShiftRight"
+    {0x7, 0x55}, //"NumpadMultiply"
+    {0x7, 0xe2}, //"AltLeft"
+    {0x7, 0x2c}, //"Space"
+    {0x7, 0x39}, //"CapsLock"
+    {0x7, 0x3a}, //"F1"
+    {0x7, 0x3b}, //"F2"
+    {0x7, 0x3c}, //"F3"
+    {0x7, 0x3d}, //"F4"
+    {0x7, 0x3e}, //"F5"
+    {0x7, 0x3f}, //"F6"
+    {0x7, 0x40}, //"F7"
+    {0x7, 0x41}, //"F8"
+    {0x7, 0x42}, //"F9"
+    {0x7, 0x43}, //"F10"
+    {0x7, 0x53}, //"NumLock"
+    {0x7, 0x47}, //"ScrollLock"
+    {0x7, 0x5f}, //"Numpad7"
+    {0x7, 0x60}, //"Numpad8"
+    {0x7, 0x61}, //"Numpad9"
+    {0x7, 0x56}, //"NumpadSubtract"
+    {0x7, 0x5c}, //"Numpad4"
+    {0x7, 0x5d}, //"Numpad5"
+    {0x7, 0x5e}, //"Numpad6"
+    {0x7, 0x57}, //"NumpadAdd"
+    {0x7, 0x59}, //"Numpad1"
+    {0x7, 0x5a}, //"Numpad2"
+    {0x7, 0x5b}, //"Numpad3"
+    {0x7, 0x62}, //"Numpad0"
+    {0x7, 0x63}, //"NumpadDecimal"
+    {0x0, 0x0}, //NULL
+    {0x7, 0x94}, //"Lang5"
+    {0x7, 0x64}, //"IntlBackslash"
+    {0x7, 0x44}, //"F11"
+    {0x7, 0x45}, //"F12"
+    {0x7, 0x87}, //"IntlRo"
+    {0x7, 0x92}, //"Lang3"
+    {0x7, 0x93}, //"Lang4"
+    {0x7, 0x8a}, //"Convert"
+    {0x7, 0x88}, //"KanaMode"
+    {0x7, 0x8b}, //"NonConvert"
+    {0x0, 0x0}, //NULL
+    {0x7, 0x58}, //"NumpadEnter"
+    {0x7, 0xe4}, //"ControlRight"
+    {0x7, 0x54}, //"NumpadDivide"
+    {0x7, 0x46}, //"PrintScreen"
+    {0x7, 0xe6}, //"AltRight"
+    {0x0, 0x0}, //NULL
+    {0x7, 0x4a}, //"Home"
+    {0x7, 0x52}, //"ArrowUp"
+    {0x7, 0x4b}, //"PageUp"
+    {0x7, 0x50}, //"ArrowLeft"
+    {0x7, 0x4f}, //"ArrowRight"
+    {0x7, 0x4d}, //"End"
+    {0x7, 0x51}, //"ArrowDown"
+    {0x7, 0x4e}, //"PageDown"
+    {0x7, 0x49}, //"Insert"
+    {0x7, 0x4c}, //"Delete"
+    {0x0, 0x0}, //NULL
+    {0x7, 0x7f}, //"AudioVolumeMute"
+    {0x7, 0x81}, //"AudioVolumeDown"
+    {0x7, 0x80}, //"AudioVolumeUp"
+    {0x7, 0x66}, //"Power"
+    {0x7, 0x67}, //"NumpadEqual"
+    {0x7, 0xd7}, //NULL
+    {0x7, 0x48}, //"Pause"
+    {0xc, 0x29f}, //"ShowAllWindows"
+    {0x7, 0x85}, //"NumpadComma"
+    {0x7, 0x90}, //"Lang1"
+    {0x7, 0x91}, //"Lang2"
+    {0x7, 0x89}, //"IntlYen"
+    {0x7, 0xe3}, //"MetaLeft"
+    {0x7, 0xe7}, //"MetaRight"
+    {0x7, 0x65}, //"ContextMenu"
+    {0xc, 0x226}, //"BrowserStop"
+    {0x7, 0x79}, //"Again"
+    {0x0, 0x0}, //NULL
+    {0x7, 0x7a}, //"Undo"
+    {0x7, 0x77}, //"Select"
+    {0x7, 0x7c}, //"Copy"
+    {0x7, 0x74}, //"Open"
+    {0x7, 0x7d}, //"Paste"
+    {0x7, 0x7e}, //"Find"
+    {0x7, 0x7b}, //"Cut"
+    {0x7, 0x75}, //"Help"
+    {0x0, 0x0}, //NULL
+    {0xc, 0x192}, //"LaunchApp2"
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x194}, //"LaunchApp1"
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x196}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x19e}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x18a}, //"LaunchMail"
+    {0xc, 0x22a}, //"BrowserFavorites"
+    {0x0, 0x0}, //NULL
+    {0xc, 0x224}, //"BrowserBack"
+    {0xc, 0x225}, //"BrowserForward"
+    {0x0, 0x0}, //NULL
+    {0xc, 0xb8}, //"Eject"
+    {0x0, 0x0}, //NULL
+    {0xc, 0xb5}, //"MediaTrackNext"
+    {0xc, 0xcd}, //"MediaPlayPause"
+    {0xc, 0xb6}, //"MediaTrackPrevious"
+    {0xc, 0xb7}, //"MediaStop"
+    {0xc, 0xb2}, //"MediaRecord"
+    {0xc, 0xb4}, //"MediaRewind"
+    {0xc, 0x8c}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x183}, //"MediaSelect"
+    {0xc, 0x223}, //"BrowserHome"
+    {0xc, 0x227}, //"BrowserRefresh"
+    {0xc, 0x94}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x7, 0xb6}, //"NumpadParenLeft"
+    {0x7, 0xb7}, //"NumpadParenRight"
+    {0xc, 0x201}, //NULL
+    {0xc, 0x279}, //NULL
+    {0x7, 0x68}, //"F13"
+    {0x7, 0x69}, //"F14"
+    {0x7, 0x6a}, //"F15"
+    {0x7, 0x6b}, //"F16"
+    {0x7, 0x6c}, //"F17"
+    {0x7, 0x6d}, //"F18"
+    {0x7, 0x6e}, //"F19"
+    {0x7, 0x6f}, //"F20"
+    {0x7, 0x70}, //"F21"
+    {0x7, 0x71}, //"F22"
+    {0x7, 0x72}, //"F23"
+    {0x7, 0x73}, //"F24"
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0xb1}, //"MediaPause"
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x2a2}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x203}, //NULL
+    {0xc, 0xb0}, //"MediaPlay"
+    {0xc, 0xb3}, //"MediaFastForward"
+    {0xc, 0xe5}, //NULL
+    {0xc, 0x208}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x221}, //"BrowserSearch"
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x70}, //"BrightnessDown"
+    {0xc, 0x6f}, //"BrightnessUp"
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x7c}, //NULL
+    {0xc, 0x7a}, //NULL
+    {0xc, 0x79}, //NULL
+    {0xc, 0x28c}, //"MailSend"
+    {0xc, 0x289}, //"MailReply"
+    {0xc, 0x28b}, //"MailForward"
+    {0xc, 0x207}, //NULL
+    {0xc, 0x1a7}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0xc, 0x75}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+    {0x0, 0x0}, //NULL
+};
 
 /* Factory function to create keyboard-handler: */
@@ -2011,13 +2271,18 @@
 
 #ifdef VBOX_WS_NIX
-void UIKeyboardHandler::handleKeyEvent(quint32 nativeScanCode, bool fRelease)
-{
+void UIKeyboardHandler::handleKeyEvent(quint32 uEvDevCode, bool fRelease)
+{
+
+    // printf("UIKeyboardHandler::handleKeyEvent %u %u\n", nativeScanCode, nativeScanCode >> 0xE0);
     if (NativeWindowSubsystem::displayServerType() == VBGHDISPLAYSERVERTYPE_PURE_WAYLAND)
     {
-        /* On Linux xcb, wayland etc has an offset of 8 in scancodes (they start from 7 instead of 0): */
-        if (!fRelease)
-            uimachine()->putScancode(nativeScanCode - 8);
-        else
-            uimachine()->putScancode((nativeScanCode - 8) | 0x80);
+        AssertMsgReturnVoid(uEvDevCode < CODE_ARRAY_LENGTH, ("Received evdev code is not in conversation table"));
+        uimachine()->putUsageCode(evcode_hid[uEvDevCode][1], evcode_hid[uEvDevCode][0], fRelease);
+        //m_pMachine->putUsageCode(sequence[i].first, sequence[i].second, false);
+    //     /* On Linux xcb, wayland etc has an offset of 8 in scancodes (they start from 7 instead of 0): */
+    //     if (!fRelease)
+    //         uimachine()->putScancode(nativeScanCode - 8);
+    //     else
+    //         uimachine()->putScancode((nativeScanCode - 8) | 0x80);
     }
 }
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h	(revision 107148)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h	(revision 107153)
@@ -122,5 +122,5 @@
 
 #ifdef VBOX_WS_NIX
-    void handleKeyEvent(quint32 nativeScanCode, bool fRelease);
+    void handleKeyEvent(quint32 uEvDevCode, bool fRelease);
 #endif
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 107148)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 107153)
@@ -96,4 +96,6 @@
 #  include <xcb/xcb.h>
 #endif
+
+#include <xkbcommon/xkbcommon.h>
 
 #ifdef DEBUG_andy
@@ -2021,5 +2023,7 @@
 void UIMachineView::keyPressEvent(QKeyEvent *pEvent)
 {
-    machineLogic()->keyboardHandler()->handleKeyEvent(pEvent->nativeScanCode(), false /* is release*/);
+    /* It looks like that QKeyEvent::nativeScanCode returns evdev codes with an offset of 8: */
+    quint32 uEvDevCode = pEvent->nativeScanCode() - 8;
+    machineLogic()->keyboardHandler()->handleKeyEvent(uEvDevCode, false /* is release*/);
     QAbstractScrollArea::keyPressEvent(pEvent);
 }
@@ -2027,5 +2031,7 @@
 void UIMachineView::keyReleaseEvent(QKeyEvent *pEvent)
 {
-    machineLogic()->keyboardHandler()->handleKeyEvent(pEvent->nativeScanCode(), true /* is release*/);
+    /* It looks like that QKeyEvent::nativeScanCode returns evdev codes with an offset of 8: */
+    quint32 uEvDevCode = pEvent->nativeScanCode() - 8;
+    machineLogic()->keyboardHandler()->handleKeyEvent(uEvDevCode, true /* is release*/);
     QAbstractScrollArea::keyReleaseEvent(pEvent);
 }
