77
88const wchar_t * WINDOW_CLASS_NAME = L" HutaoNativeHotKeyActionWindowClass" ;
99
10- UINT HutaoNativeHotKeyAction::s_nextHotKeyId = 0x4000 ; // 从0x4000开始,避免与系统热键冲突
10+ UINT HutaoNativeHotKeyAction::s_nextHotKeyId = 0x4000 ;
1111
1212HutaoNativeHotKeyAction::HutaoNativeHotKeyAction (HutaoNativeHotKeyActionKind kind, HutaoNativeHotKeyActionCallback callback, GCHandle userData)
1313 : m_kind(kind)
@@ -83,7 +83,7 @@ LRESULT CALLBACK HutaoNativeHotKeyAction::WndProc(HWND hWnd, UINT message, WPARA
8383 HutaoNativeHotKeyAction* pThis = reinterpret_cast <HutaoNativeHotKeyAction*>(GetWindowLongPtrW (hWnd, GWLP_USERDATA));
8484 if (pThis != nullptr )
8585 {
86- if (message == WM_HOTKEY)
86+ if (message == WM_HOTKEY && pThis-> m_vk != 255 )
8787 {
8888 if (static_cast <int >(wParam) == pThis->motKeyId )
8989 {
@@ -103,7 +103,6 @@ LRESULT CALLBACK HutaoNativeHotKeyAction::WndProc(HWND hWnd, UINT message, WPARA
103103 pThis->ExecuteAction ();
104104 }
105105
106- // 调用回调函数通知状态变化
107106 if (pThis->m_callback .has_value ())
108107 {
109108 pThis->m_callback .value ()(!wasRunning ? TRUE : FALSE , pThis->m_userData );
@@ -139,12 +138,11 @@ void HutaoNativeHotKeyAction::ExecuteAction()
139138{
140139 if (m_isRunning.load ())
141140 {
142- return ; // 已经在运行
141+ return ;
143142 }
144143
145144 m_isRunning.store (true );
146145
147- // 启动新线程执行动作
148146 m_actionThread = std::thread ([this ]() {
149147 while (m_isRunning.load ())
150148 {
@@ -157,7 +155,6 @@ void HutaoNativeHotKeyAction::ExecuteAction()
157155 SimulateKeyPress ();
158156 }
159157
160- // 延迟一段时间(例如50ms,即每秒20次)
161158 std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
162159 }
163160 });
@@ -175,14 +172,11 @@ void HutaoNativeHotKeyAction::StopAction()
175172
176173void HutaoNativeHotKeyAction::SimulateMouseClick ()
177174{
178- // 模拟鼠标左键点击
179175 INPUT inputs[2 ] = {0 };
180176
181- // 按下左键
182177 inputs[0 ].type = INPUT_MOUSE;
183178 inputs[0 ].mi .dwFlags = MOUSEEVENTF_LEFTDOWN;
184179
185- // 释放左键
186180 inputs[1 ].type = INPUT_MOUSE;
187181 inputs[1 ].mi .dwFlags = MOUSEEVENTF_LEFTUP;
188182
@@ -191,15 +185,12 @@ void HutaoNativeHotKeyAction::SimulateMouseClick()
191185
192186void HutaoNativeHotKeyAction::SimulateKeyPress ()
193187{
194- // 模拟F键按下(VK_F为0x46)
195188 INPUT inputs[2 ] = {0 };
196189
197- // 按下F键
198190 inputs[0 ].type = INPUT_KEYBOARD;
199- inputs[0 ].ki .wVk = 0x46 ; // VK_F
191+ inputs[0 ].ki .wVk = 0x46 ;
200192 inputs[0 ].ki .dwFlags = 0 ;
201193
202- // 释放F键
203194 inputs[1 ].type = INPUT_KEYBOARD;
204195 inputs[1 ].ki .wVk = 0x46 ; // VK_F
205196 inputs[1 ].ki .dwFlags = KEYEVENTF_KEYUP;
@@ -241,12 +232,11 @@ HRESULT __stdcall HutaoNativeHotKeyAction::SetIsEnabled(BOOL isEnabled)
241232
242233 if (newEnabled == m_enabled)
243234 {
244- return S_OK; // 状态没有变化
235+ return S_OK;
245236 }
246237
247238 if (newEnabled)
248239 {
249- // 启用热键
250240 if (m_hWnd == nullptr )
251241 {
252242 m_hWnd = CreateMessageWindow ();
@@ -265,7 +255,6 @@ HRESULT __stdcall HutaoNativeHotKeyAction::SetIsEnabled(BOOL isEnabled)
265255 }
266256 else
267257 {
268- // 禁用热键
269258 UnregisterHotKey ();
270259 StopAction ();
271260 }
0 commit comments