@@ -41,98 +41,138 @@ messages (as those are the keys being captured). A separate thread is
4141created to send out the key(s) to send to the os.
4242*/
4343LRESULT CALLBACK LowLevelKeyboardProc (int nCode, WPARAM wParam, LPARAM lParam)
44- {
45- KBDLLHOOKSTRUCT *pHook = reinterpret_cast <KBDLLHOOKSTRUCT*>(lParam) ;
44+ {
45+ DWORD vkCode = 0 ;
4646 bool bSentInput = false ;
4747
4848 bool bAlt = 0 != (GetAsyncKeyState (VK_MENU) & 0x8000 );
4949 bool bControl = 0 != (GetAsyncKeyState (VK_CONTROL) & 0x8000 );
5050 bool bShift = 0 != (GetAsyncKeyState (VK_SHIFT) & 0x8000 );
5151
52- // don't catch injected keys
53- if (!(pHook->flags & LLKHF_INJECTED)
54- && HC_ACTION == nCode)
52+ // get the correct virtual key
53+ switch (wParam)
54+ {
55+ case WM_MBUTTONDOWN:
56+ case WM_MBUTTONUP:
57+ {
58+ // mouse mid
59+ vkCode = 0x04 ;
60+ break ;
61+ }
62+ case WM_XBUTTONDOWN:
63+ case WM_XBUTTONUP:
64+ {
65+ // mouse x
66+ MSLLHOOKSTRUCT* pMSHook = reinterpret_cast <MSLLHOOKSTRUCT*>(lParam);
67+ UINT xBtn = GET_XBUTTON_WPARAM (pMSHook->mouseData );
68+ vkCode = xBtn == XBUTTON1 ? 0x05 : 0x06 ;
69+ break ;
70+
71+ }
72+ case WM_KEYDOWN:
73+ case WM_SYSKEYDOWN:
74+ case WM_KEYUP:
75+ case WM_SYSKEYUP:
76+ {
77+ // keyboard
78+ KBDLLHOOKSTRUCT* pKBHook = reinterpret_cast <KBDLLHOOKSTRUCT*>(lParam);
79+
80+ // don't catch injected keys
81+ if (pKBHook->flags & LLKHF_INJECTED && HC_ACTION != nCode)
82+ return CallNextHookEx (NULL , nCode, wParam, lParam);
83+
84+ vkCode = pKBHook->vkCode ;
85+ break ;
86+ }
87+ }
88+
89+ if (!vkCode)
90+ return CallNextHookEx (NULL , nCode, wParam, lParam); // invalid or unsupported event
91+
92+ // NOTE: these are in while loops because a key may have multiple mappings due to the flag keys (shift/alt/ctrl)
93+ switch (wParam)
5594 {
56- // NOTE: these are in while loops because a key may have multiple mappings due to the flag keys (shift/alt/ctrl)
57- switch (wParam)
95+ case WM_KEYDOWN:
96+ case WM_SYSKEYDOWN:
97+ case WM_MBUTTONDOWN:
98+ case WM_XBUTTONDOWN:
99+ // detect a keydown that matches a remaped key (and start the input thread to respond accordingly then indicate to the OS that the key has been handled)
58100 {
59- case WM_KEYDOWN:
60- case WM_SYSKEYDOWN:
61- // detect a keydown that matches a remaped key (and start the input thread to respond accordingly then indicate to the OS that the key has been handled)
62- {
63- // NOTE: key down events will come in while a key is being held
101+ // NOTE: key down events will come in while a key is being held
64102
65- const RemapEntryContainerListItem* pKeyListItem = g_KeyTranslationTable[pHook->vkCode ];
66- while (NULL != pKeyListItem)
103+ const RemapEntryContainerListItem* pKeyListItem = g_KeyTranslationTable[vkCode];
104+ while (NULL != pKeyListItem)
105+ {
106+ const InputConfig* pKeyDef = &pKeyListItem->pEntryContainer ->pEntry ->inputConfig ;
107+ if ((bAlt == pKeyDef->inputFlag .bAlt ) &&
108+ (bControl == pKeyDef->inputFlag .bControl ) &&
109+ (bShift == pKeyDef->inputFlag .bShift )
110+ && !pKeyDef->inputFlag .bLongPress )
67111 {
68- const InputConfig* pKeyDef = &pKeyListItem->pEntryContainer ->pEntry ->inputConfig ;
69- if ((bAlt == pKeyDef->inputFlag .bAlt ) &&
70- (bControl == pKeyDef->inputFlag .bControl ) &&
71- (bShift == pKeyDef->inputFlag .bShift )
72- && !pKeyDef->inputFlag .bLongPress )
73- {
74112#ifdef _DEBUG
75- char * pInputConfigDescription = GetInputConfigDescription (*pKeyDef);
76- LogDebugMessage (" Detected Key Press: %s Outputs: %d" , pInputConfigDescription, pKeyListItem->pEntryContainer ->pEntry ->outputCount );
77- free (pInputConfigDescription);
113+ char * pInputConfigDescription = GetInputConfigDescription (*pKeyDef);
114+ LogDebugMessage (" Detected Key Press: %s Outputs: %d" , pInputConfigDescription, pKeyListItem->pEntryContainer ->pEntry ->outputCount );
115+ free (pInputConfigDescription);
78116#endif
79- // If there is NOT an existing thread OR the existing thread is running a repeat another key press is allowed
80- if (NULL == pKeyListItem->pEntryContainer ->pEntryState ->threadHandle || pKeyListItem->pEntryContainer ->pEntryState ->bRepeating )
81- {
82- pKeyListItem->pEntryContainer ->pEntryState ->threadHandle = CreateThread (NULL , 0 , SendInputThread, pKeyListItem->pEntryContainer , 0 , NULL );
83- }
84- // block further processing with the inputs
85- bSentInput = true ;
86- break ;
87- }
88- if (!bAlt
89- && !bControl
90- && !bShift
91- && pKeyDef->inputFlag .bLongPress )
117+ // If there is NOT an existing thread OR the existing thread is running a repeat another key press is allowed
118+ if (NULL == pKeyListItem->pEntryContainer ->pEntryState ->threadHandle || pKeyListItem->pEntryContainer ->pEntryState ->bRepeating )
92119 {
93- ProcessLongPressKeyDown (pKeyDef, pKeyListItem);
94- // block further processing with the inputs
95- bSentInput = true ;
96- break ;
120+ pKeyListItem->pEntryContainer ->pEntryState ->threadHandle = CreateThread (NULL , 0 , SendInputThread, pKeyListItem->pEntryContainer , 0 , NULL );
97121 }
98- pKeyListItem = pKeyListItem->pNext ;
122+ // block further processing with the inputs
123+ bSentInput = true ;
124+ break ;
99125 }
126+ if (!bAlt
127+ && !bControl
128+ && !bShift
129+ && pKeyDef->inputFlag .bLongPress )
130+ {
131+ ProcessLongPressKeyDown (pKeyDef, pKeyListItem);
132+ // block further processing with the inputs
133+ bSentInput = true ;
134+ break ;
135+ }
136+ pKeyListItem = pKeyListItem->pNext ;
100137 }
101- break ;
102- case WM_KEYUP:
103- case WM_SYSKEYUP:
104- // detect a keyup that matches a remaped key (and indicate to the OS that the key has been handled)
138+ }
139+ break ;
140+ case WM_KEYUP:
141+ case WM_SYSKEYUP:
142+ case WM_MBUTTONUP:
143+ case WM_XBUTTONUP:
144+ // detect a keyup that matches a remaped key (and indicate to the OS that the key has been handled)
145+ {
146+ RemapEntryContainerListItem* pKeyListItem = g_KeyTranslationTable[vkCode];
147+ while (NULL != pKeyListItem)
105148 {
106- RemapEntryContainerListItem* pKeyListItem = g_KeyTranslationTable[pHook->vkCode ];
107- while (NULL != pKeyListItem)
149+ InputConfig* pKeyDef = &pKeyListItem->pEntryContainer ->pEntry ->inputConfig ;
150+ if (bAlt == pKeyDef->inputFlag .bAlt
151+ && bControl == pKeyDef->inputFlag .bControl
152+ && bShift == pKeyDef->inputFlag .bShift
153+ && !pKeyDef->inputFlag .bLongPress )
108154 {
109- InputConfig* pKeyDef = &pKeyListItem->pEntryContainer ->pEntry ->inputConfig ;
110- if (bAlt == pKeyDef->inputFlag .bAlt
111- && bControl == pKeyDef->inputFlag .bControl
112- && bShift == pKeyDef->inputFlag .bShift
113- && !pKeyDef->inputFlag .bLongPress )
114- {
115- // block further processing with the inputs
116- bSentInput = true ;
117- break ;
118- }
119- if (!bAlt
120- && !bControl
121- && !bShift
122- && pKeyDef->inputFlag .bLongPress )
123- {
124- ProcessLongPressKeyUp (pKeyDef);
125- // block further processing with the inputs
126- bSentInput = true ;
127- break ;
128- }
129- pKeyListItem = pKeyListItem->pNext ;
155+ // block further processing with the inputs
156+ bSentInput = true ;
157+ break ;
158+ }
159+ if (!bAlt
160+ && !bControl
161+ && !bShift
162+ && pKeyDef->inputFlag .bLongPress )
163+ {
164+ ProcessLongPressKeyUp (pKeyDef);
165+ // block further processing with the inputs
166+ bSentInput = true ;
167+ break ;
130168 }
169+ pKeyListItem = pKeyListItem->pNext ;
131170 }
132- break ;
133171 }
134- LogDebugMessage ( " LowLevelKeyboardProc Complete " ) ;
172+ break ;
135173 }
174+ LogDebugMessage (" LowLevelKeyboardProc Complete" );
175+
136176 return bSentInput ? 1 : CallNextHookEx (NULL , nCode, wParam, lParam);
137177}
138178
0 commit comments