From: <re...@us...> - 2007-06-17 16:24:19
|
Revision: 189 http://svn.sourceforge.net/modplug/?rev=189&view=rev Author: rewbs Date: 2007-06-17 09:24:14 -0700 (Sun, 17 Jun 2007) Log Message: ----------- Applying Pelya's patch with minor formatting and variable/method name changes. Thanks Pelya! + <Pelya> Allow Window key as a modifier in the keyboard configuration. Disables start menu pop-up when pressing the Win key if and only if it used in the active keyboard configuration. + <Pelya> Disables NumLock/CapsLock/ScrollLock lamps on keyboard if and only if they are used in the active keyboard configuration. The lamps will blink anyway - can't help it until we start using DirectInput. Modified Paths: -------------- trunk/OpenMPT/mptrack/CommandSet.cpp trunk/OpenMPT/mptrack/InputHandler.cpp trunk/OpenMPT/mptrack/InputHandler.h trunk/OpenMPT/packageTemplate/Installation.txt Modified: trunk/OpenMPT/mptrack/CommandSet.cpp =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp 2007-05-27 17:47:34 UTC (rev 188) +++ trunk/OpenMPT/mptrack/CommandSet.cpp 2007-06-17 16:24:14 UTC (rev 189) @@ -2814,7 +2814,8 @@ for (int k=0; k<commands[curCmd].kcList.GetSize(); k++) { curKc = commands[curCmd].kcList[k]; - if ((!curKc.mod) || (curKc.code!=VK_SHIFT && curKc.code!=VK_CONTROL && curKc.code!=VK_MENU && curKc.code!=0)) + if ((!curKc.mod) || (curKc.code!=VK_SHIFT && curKc.code!=VK_CONTROL && curKc.code!=VK_MENU && curKc.code!=0 && + curKc.code!=VK_LWIN && curKc.code!=VK_RWIN )) // Feature: use Windows keys as modifier keys { report+="Error! " + GetCommandText((CommandID)curCmd) + " must be a modifier (shift/ctrl/alt), but is currently " + GetKeyText(inKc.mod, inKc.code) + "\r\n"; //replace with dummy @@ -2880,6 +2881,7 @@ case VK_SHIFT: return HOTKEYF_SHIFT; case VK_MENU: return HOTKEYF_ALT; case VK_CONTROL: return HOTKEYF_CONTROL; + case VK_LWIN: case VK_RWIN: return HOTKEYF_EXT; // Feature: use Windows keys as modifier keys default: /*DEBUG: ASSERT(false);*/ return 0; //can only get modifier for modifier key } @@ -2897,9 +2899,6 @@ //Clear map memset(km, -1, sizeof(kcNull)*KeyMapSize); -// km.RemoveAll(); -// km.InitHashTable(700423); - //Copy commandlist content into map: for (UINT cmd=0; cmd<kcNumCommands; cmd++) @@ -3216,6 +3215,7 @@ if (mod & HOTKEYF_SHIFT) text.Append("Shift+"); if (mod & HOTKEYF_CONTROL) text.Append("Ctrl+"); if (mod & HOTKEYF_ALT) text.Append("Alt+"); + if (mod & HOTKEYF_EXT) text.Append("Win+"); // Feature: use Windows keys as modifier keys return text; } @@ -3436,4 +3436,4 @@ return conflict; } -//end rewbs.customKeys \ No newline at end of file +//end rewbs.customKeys Modified: trunk/OpenMPT/mptrack/InputHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/InputHandler.cpp 2007-05-27 17:47:34 UTC (rev 188) +++ trunk/OpenMPT/mptrack/InputHandler.cpp 2007-06-17 16:24:14 UTC (rev 189) @@ -35,6 +35,8 @@ //Get Keymap activeCommandSet->GenKeyMap(keyMap); + SetupSpecialKeyInterception(); // Feature: use Windows keys as modifier keys, intercept special keys + m_nSkipGeneratedKeypresses = 0; m_bDistinguishControls = false; m_bDistinguishShifts = false; @@ -54,38 +56,37 @@ //-------------------------------------------------------------- - - CommandID CInputHandler::GeneralKeyEvent(InputTargetContext context, int code, WPARAM wParam , LPARAM lParam) - { CommandID executeCommand = kcNull; KeyEventType keyEventType; - if (code == HC_ACTION) - { + if (code == HC_ACTION) { //Get the KeyEventType (key up, key down, key repeat) DWORD scancode = lParam >> 16; - if ((scancode & 0xC000) == 0xC000) keyEventType = kKeyEventUp; - else if ((scancode & 0xC000) == 0x0000) keyEventType = kKeyEventDown; - else keyEventType = kKeyEventRepeat; + if ((scancode & 0xC000) == 0xC000) { + keyEventType = kKeyEventUp; + } else if ((scancode & 0xC000) == 0x0000) { + keyEventType = kKeyEventDown; + } else { + keyEventType = kKeyEventRepeat; + } - //Catch modifier change (ctrl, alt, shift) - Only check on keyDown or keyUp. - if (keyEventType == kKeyEventUp || keyEventType == kKeyEventDown) - { + // Catch modifier change (ctrl, alt, shift) - Only check on keyDown or keyUp. + // NB: we want to catch modifiers even when the input handler is locked + if (keyEventType == kKeyEventUp || keyEventType == kKeyEventDown) { scancode =(lParam >> 16) & 0x1FF; CatchModifierChange(wParam, keyEventType, scancode); } - if (keyEventType == kKeyEventUp) - keyEventType=kKeyEventUp; - - if (!Bypass()) // If bypassing, we want to catch modifiers but not execute commands + if (!InterceptSpecialKeys( wParam, lParam ) && !Bypass()) { + // only execute command when the input handler is not locked + // and the input is not a consequence of special key interception. executeCommand = keyMap[context][modifierMask][wParam][keyEventType]; + } } - if (m_pMainFrm && executeCommand != kcNull) - { + if (m_pMainFrm && executeCommand != kcNull) { m_pMainFrm->PostMessage(WM_MOD_KEYCOMMAND, executeCommand, wParam); } @@ -111,7 +112,65 @@ return executeCommand; } +// Feature: use Windows keys as modifier keys, intercept special keys +bool CInputHandler::InterceptSpecialKeys( UINT nChar , UINT nFlags ) +{ + KeyEventType keyEventType = GetKeyEventType( HIWORD(nFlags) ); + enum { VK_NonExistentKey = VK_F24+1 }; + + if( nChar == VK_NonExistentKey ) { + return true; + } else if( m_bInterceptWindowsKeys && ( nChar == VK_LWIN || nChar == VK_RWIN ) ) { + if( keyEventType == kKeyEventDown ) { + INPUT inp[2]; + inp[0].type = inp[1].type = INPUT_KEYBOARD; + inp[0].ki.time = inp[1].ki.time = 0; + inp[0].ki.dwExtraInfo = inp[0].ki.dwExtraInfo = 0; + inp[0].ki.wVk = inp[1].ki.wVk = VK_NonExistentKey; + inp[0].ki.wScan = inp[1].ki.wScan = 0; + inp[0].ki.dwFlags = 0; + inp[1].ki.dwFlags = KEYEVENTF_KEYUP; + SendInput( 2, inp, sizeof(INPUT) ); + } + } + + if( ( nChar == VK_NUMLOCK && m_bInterceptNumLock ) || + ( nChar == VK_CAPITAL && m_bInterceptCapsLock ) || + ( nChar == VK_SCROLL && m_bInterceptScrollLock ) ) { + if( m_nSkipGeneratedKeypresses > 0 ) { + m_nSkipGeneratedKeypresses -- ; + return true; + } else if( keyEventType == kKeyEventDown ) { + m_nSkipGeneratedKeypresses = 2; + INPUT inp[2]; + inp[0].type = inp[1].type = INPUT_KEYBOARD; + inp[0].ki.time = inp[1].ki.time = 0; + inp[0].ki.dwExtraInfo = inp[0].ki.dwExtraInfo = 0; + inp[0].ki.wVk = inp[1].ki.wVk = nChar; + inp[0].ki.wScan = inp[1].ki.wScan = 0; + inp[0].ki.dwFlags = KEYEVENTF_KEYUP; + inp[1].ki.dwFlags = 0; + SendInput( 2, inp, sizeof(INPUT) ); + } + } + return false; +}; +void CInputHandler::SetupSpecialKeyInterception() +{ + m_bInterceptWindowsKeys = m_bInterceptNumLock = m_bInterceptCapsLock = m_bInterceptScrollLock = false; + for( int context=0; context<sizeof(keyMap)/sizeof(keyMap[0]); context++ ) + for( int mod=0; mod<sizeof(keyMap[0])/sizeof(keyMap[0][0]); mod++ ) + for( int key=0; key<sizeof(keyMap[0][0])/sizeof(keyMap[0][0][0]); key++ ) + for( int kevent=0; kevent<sizeof(keyMap[0][0][0])/sizeof(keyMap[0][0][0][0]); kevent++ ) { + if( keyMap[context][mod][key][kevent] == kcNull ) continue; + if( mod == HOTKEYF_EXT ) m_bInterceptWindowsKeys = true; + if( key == VK_NUMLOCK ) m_bInterceptNumLock = true; + if( key == VK_CAPITAL ) m_bInterceptCapsLock = true; + if( key == VK_SCROLL ) m_bInterceptScrollLock = true; + }; +}; + //-------------------------------------------------------------- //Deal with Modifier keypresses. Private surouting used above. bool CInputHandler::CatchModifierChange(WPARAM wParam, KeyEventType keyEventType, int scancode) @@ -156,6 +215,9 @@ */ tempModifierMask |= HOTKEYF_ALT; break; // } + case VK_LWIN: case VK_RWIN: // Feature: use Windows keys as modifier keys + tempModifierMask |= HOTKEYF_EXT; + break; } if (tempModifierMask) //This keypress just changed the modifier mask @@ -236,9 +298,9 @@ if (mask & HOTKEYF_CONTROL) Log("Ctrl On"); else Log("Ctrl --"); if (mask & HOTKEYF_SHIFT) Log("\tShft On"); else Log("\tShft --"); if (mask & HOTKEYF_ALT) Log("\tAlt On\n"); else Log("\tAlt --\n"); + if (mask & HOTKEYF_EXT) Log("\tWin On\n"); else Log("\tWin --\n"); // Feature: use Windows keys as modifier keys } - KeyEventType CInputHandler::GetKeyEventType(UINT nFlags) { if (nFlags & TRANSITIONBIT) //Key released @@ -439,6 +501,7 @@ { activeCommandSet->Copy(newSet); activeCommandSet->GenKeyMap(keyMap); + SetupSpecialKeyInterception(); // Feature: use Windows keys as modifier keys, intercept special keys UpdateMainMenu(); } @@ -488,4 +551,4 @@ return true; return false; -} \ No newline at end of file +} Modified: trunk/OpenMPT/mptrack/InputHandler.h =================================================================== --- trunk/OpenMPT/mptrack/InputHandler.h 2007-05-27 17:47:34 UTC (rev 188) +++ trunk/OpenMPT/mptrack/InputHandler.h 2007-06-17 16:24:14 UTC (rev 189) @@ -66,6 +66,10 @@ bool m_bNoAltMenu; bool m_bDistinguishControls, m_bDistinguishShifts, m_bDistinguishAlts; bool CatchModifierChange(WPARAM wParam, KeyEventType keyEventType, int scancode); + bool m_bInterceptWindowsKeys, m_bInterceptNumLock, m_bInterceptCapsLock, m_bInterceptScrollLock; + int m_nSkipGeneratedKeypresses; + bool InterceptSpecialKeys( UINT nChar , UINT nFlags ); + void SetupSpecialKeyInterception(); public: CCommandSet *activeCommandSet; @@ -88,3 +92,4 @@ bool SetITEffects(void); }; + Modified: trunk/OpenMPT/packageTemplate/Installation.txt =================================================================== --- trunk/OpenMPT/packageTemplate/Installation.txt 2007-05-27 17:47:34 UTC (rev 188) +++ trunk/OpenMPT/packageTemplate/Installation.txt 2007-06-17 16:24:14 UTC (rev 189) @@ -1,5 +1,6 @@ OpenMPT development build - Installation notes ---------------------------------------------- -. If you have an existing installation of OpenMPT and wish to re-use its settings, copy your mptrack.ini to this directory. -. If not, you're done: just launch mptrack.exe. +. If you have an existing installation of OpenMPT and wish to re-use its settings, + copy your mptrack.ini and plugin.cache to the directory into which you extract the archive. +. If not, you're done: just extract the archive and launch mptrack.exe. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |