diff --git a/hotkeyedit.cc b/hotkeyedit.cc index b2a366c3..cf255dde 100644 --- a/hotkeyedit.cc +++ b/hotkeyedit.cc @@ -4,6 +4,10 @@ #include "hotkeyedit.hh" #include +#ifdef Q_OS_WIN +#include +#endif + HotKeyEdit::HotKeyEdit( QWidget * parent ): QLineEdit( parent ), currentModifiers( 0 ), currentKey1( 0 ), currentKey2( 0 ), @@ -53,6 +57,15 @@ void HotKeyEdit::keyPressEvent( QKeyEvent * event ) int key = event->key(); Qt::KeyboardModifiers modifiers = event->modifiers() & ~Qt::KeypadModifier; +#ifdef Q_OS_WIN + if( objectName() == "mainWindowHotkey" || objectName() == "clipboardHotkey" ) + { + int newkey = VkeyToQTkey( event->nativeVirtualKey() ); + if( newkey ) + key = newkey; + } +#endif + switch( key ) { case 0: @@ -127,3 +140,81 @@ bool HotKeyEdit::eventFilter( QObject *, QEvent * event ) } return false; } + +#ifdef Q_OS_WIN + +int HotKeyEdit::VkeyToQTkey( quint32 vkey ) +{ + if ( vkey >= Qt::Key_A && vkey <= Qt::Key_Z) + return vkey; + + switch( vkey ) + { + case VK_NUMPAD0: return Qt::Key_0; + case VK_NUMPAD1: return Qt::Key_1; + case VK_NUMPAD2: return Qt::Key_2; + case VK_NUMPAD3: return Qt::Key_3; + case VK_NUMPAD4: return Qt::Key_4; + case VK_NUMPAD5: return Qt::Key_5; + case VK_NUMPAD6: return Qt::Key_6; + case VK_NUMPAD7: return Qt::Key_7; + case VK_NUMPAD8: return Qt::Key_8; + case VK_NUMPAD9: return Qt::Key_9; + case VK_DIVIDE: return Qt::Key_Slash; + case VK_MULTIPLY: return Qt::Key_Asterisk; + case VK_SUBTRACT: return Qt::Key_Minus; + case VK_ADD: return Qt::Key_Plus; + case VK_DECIMAL: return Qt::Key_Period; + case VK_F1: return Qt::Key_F1; + case VK_F2: return Qt::Key_F2; + case VK_F3: return Qt::Key_F3; + case VK_F4: return Qt::Key_F4; + case VK_F5: return Qt::Key_F5; + case VK_F6: return Qt::Key_F6; + case VK_F7: return Qt::Key_F7; + case VK_F8: return Qt::Key_F8; + case VK_F9: return Qt::Key_F9; + case VK_F10: return Qt::Key_F10; + case VK_F11: return Qt::Key_F11; + case VK_F12: return Qt::Key_F12; + case VK_F13: return Qt::Key_F13; + case VK_F14: return Qt::Key_F14; + case VK_F15: return Qt::Key_F15; + case VK_F16: return Qt::Key_F16; + case VK_F17: return Qt::Key_F17; + case VK_F18: return Qt::Key_F18; + case VK_F19: return Qt::Key_F19; + case VK_F20: return Qt::Key_F20; + case VK_F21: return Qt::Key_F21; + case VK_F22: return Qt::Key_F22; + case VK_F23: return Qt::Key_F23; + case VK_F24: return Qt::Key_F24; + case 0x30: return Qt::Key_ParenRight; + case 0x31: return Qt::Key_Exclam; + case 0x32: return Qt::Key_At; + case 0x33: return Qt::Key_NumberSign; + case 0x34: return Qt::Key_Dollar; + case 0x35: return Qt::Key_Percent; + case 0x36: return Qt::Key_AsciiCircum; + case 0x37: return Qt::Key_Ampersand; + case 0x38: return Qt::Key_copyright; + case 0x39: return Qt::Key_ParenLeft; + case VK_OEM_MINUS: return Qt::Key_Underscore; + case VK_OEM_PLUS: return Qt::Key_Equal; + case VK_OEM_1: return Qt::Key_Semicolon; + case VK_OEM_2: return Qt::Key_Question; + case VK_OEM_3: return Qt::Key_QuoteLeft; + case VK_OEM_4: return Qt::Key_BracketLeft; + case VK_OEM_5: return Qt::Key_Backslash; + case VK_OEM_6: return Qt::Key_BracketRight; + case VK_OEM_7: return Qt::Key_Apostrophe; + case VK_OEM_COMMA: return Qt::Key_Less; + case VK_OEM_PERIOD: return Qt::Key_Greater; + + default:; + } + + return 0; +} + +#endif diff --git a/hotkeyedit.hh b/hotkeyedit.hh index 086cf1e7..512c0319 100644 --- a/hotkeyedit.hh +++ b/hotkeyedit.hh @@ -33,6 +33,9 @@ private: void renderCurrentValue(); bool eventFilter( QObject *, QEvent * event ); +#ifdef Q_OS_WIN + int VkeyToQTkey( quint32 vkey ); +#endif }; #endif diff --git a/hotkeywrapper.cc b/hotkeywrapper.cc index b658c1ee..0cf1ab3d 100644 --- a/hotkeywrapper.cc +++ b/hotkeywrapper.cc @@ -304,7 +304,7 @@ bool HotkeyWrapper::winEvent ( MSG * message, long * result ) quint32 HotkeyWrapper::nativeKey(int key) { if (key >= Qt::Key_0 && key <= Qt::Key_9) - return key; + return VK_NUMPAD0 + ( key - Qt::Key_0 ); if (key >= Qt::Key_A && key <= Qt::Key_Z) return key; @@ -359,6 +359,33 @@ quint32 HotkeyWrapper::nativeKey(int key) case Qt::Key_F22: return VK_F22; case Qt::Key_F23: return VK_F23; case Qt::Key_F24: return VK_F24; + case Qt::Key_Colon: + case Qt::Key_Semicolon: return VK_OEM_1; + case Qt::Key_Question: return VK_OEM_2; + case Qt::Key_AsciiTilde: + case Qt::Key_QuoteLeft: return VK_OEM_3; + case Qt::Key_BraceLeft: + case Qt::Key_BracketLeft: return VK_OEM_4; + case Qt::Key_Bar: + case Qt::Key_Backslash: return VK_OEM_5; + case Qt::Key_BraceRight: + case Qt::Key_BracketRight: return VK_OEM_6; + case Qt::Key_QuoteDbl: + case Qt::Key_Apostrophe: return VK_OEM_7; + case Qt::Key_Less: return VK_OEM_COMMA; + case Qt::Key_Greater: return VK_OEM_PERIOD; + case Qt::Key_Equal: return VK_OEM_PLUS; + case Qt::Key_ParenRight: return 0x30; + case Qt::Key_Exclam: return 0x31; + case Qt::Key_At: return 0x32; + case Qt::Key_NumberSign: return 0x33; + case Qt::Key_Dollar: return 0x34; + case Qt::Key_Percent: return 0x35; + case Qt::Key_AsciiCircum: return 0x36; + case Qt::Key_Ampersand: return 0x37; + case Qt::Key_copyright: return 0x38; + case Qt::Key_ParenLeft: return 0x39; + case Qt::Key_Underscore: return VK_OEM_MINUS; default:; }