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_*)
QString GetKeyName
(unsigned int virtualKey
) {
unsigned int scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);
// because MapVirtualKey strips the extended bit for some keys
switch (virtualKey)
{
case VK_LEFT: case VK_UP: case VK_RIGHT: case VK_DOWN: // arrow keys
case VK_PRIOR: case VK_NEXT: // page up and page down
case VK_END: case VK_HOME:
case VK_INSERT: case VK_DELETE:
case VK_DIVIDE: // numpad slash
case VK_NUMLOCK:
{
scanCode |= 0x100; // set extended bit
break;
}
}
char* keyName = new char[256];
if (GetKeyNameTextA(scanCode << 16, keyName, 256) != 0)
{
name = keyName;
}
delete[] keyName;
return name;
}
QString GetKeyName(unsigned int virtualKey)
{
unsigned int scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);
// because MapVirtualKey strips the extended bit for some keys
switch (virtualKey)
{
case VK_LEFT: case VK_UP: case VK_RIGHT: case VK_DOWN: // arrow keys
case VK_PRIOR: case VK_NEXT: // page up and page down
case VK_END: case VK_HOME:
case VK_INSERT: case VK_DELETE:
case VK_DIVIDE: // numpad slash
case VK_NUMLOCK:
{
scanCode |= 0x100; // set extended bit
break;
}
}
char* keyName = new char[256];
QString name;
if (GetKeyNameTextA(scanCode << 16, keyName, 256) != 0)
{
name = keyName;
}
delete[] keyName;
return name;
}
To copy to clipboard, switch view to plain text mode
can you help me ?
Bookmarks