Results 1 to 3 of 3

Thread: Is there a way to convert Qt Key codes to Virtual-key codes (of windows)

  1. #1
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Is there a way to convert Qt Key codes to Virtual-key codes (of windows)

    I'm making a system of hotkeys and need to make a "input" for it, like the win32 HOTKEY_CLASS.

    But, the keys returned in Qt, with a example, using F1
    return: 16777232
    and the virtual key code of VK_F1 is 112

    How can I translate Qt key to VK_* or how to make a control that can handle all hotkeys combinations ?

    I'm subclassing line edit, and some of keys works, but, if I use Home, End, F* keys, it doesn't work, and return big numbers too like Qt::Key_F1 (not the same number).
    And if I use Ctrl + Shift + Alt + L (or S) don't work... (with A, Z, Q, etc works)

    I'm using this code to get the keys names (and it works when using VK_*)

    Qt Code:
    1. QString GetKeyName(unsigned int virtualKey)
    2. {
    3. unsigned int scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);
    4.  
    5. // because MapVirtualKey strips the extended bit for some keys
    6. switch (virtualKey)
    7. {
    8. case VK_LEFT: case VK_UP: case VK_RIGHT: case VK_DOWN: // arrow keys
    9. case VK_PRIOR: case VK_NEXT: // page up and page down
    10. case VK_END: case VK_HOME:
    11. case VK_INSERT: case VK_DELETE:
    12. case VK_DIVIDE: // numpad slash
    13. case VK_NUMLOCK:
    14. {
    15. scanCode |= 0x100; // set extended bit
    16. break;
    17. }
    18. }
    19.  
    20. char* keyName = new char[256];
    21. QString name;
    22.  
    23. if (GetKeyNameTextA(scanCode << 16, keyName, 256) != 0)
    24. {
    25. name = keyName;
    26. }
    27.  
    28. delete[] keyName;
    29.  
    30. return name;
    31. }
    To copy to clipboard, switch view to plain text mode 

    can you help me ?
    Last edited by rsilva; 22nd April 2011 at 00:39.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there a way to convert Qt Key codes to Virtual-key codes (of windows)

    Trap QKeyEvent and use nativeVirtualKey() ?

    See qt\src\gui\kernel\qkeymapper_win.cpp

  3. #3
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is there a way to convert Qt Key codes to Virtual-key codes (of windows)

    Thank you, it worked with the nativeVirtualKey... i didn't know about it.
    And now my problem trying to use a common control class is solved too, because I can do a similar control with this ^^

Similar Threads

  1. ISO 639-2 language codes
    By brixton in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2010, 21:52
  2. Replies: 1
    Last Post: 5th November 2010, 05:22
  3. Error codes in QtXml
    By suneel1310 in forum Qt Programming
    Replies: 0
    Last Post: 7th September 2010, 08:39
  4. QR codes
    By jcr in forum General Programming
    Replies: 0
    Last Post: 16th May 2006, 05:02
  5. Key codes
    By impeteperry in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 18:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.