加键盘触发键 F9 绕过鼠标键检测异常; 钩子安装状态/事件计数加入诊断

This commit is contained in:
kedou 2026-08-05 22:56:53 +08:00
parent 2c44ebb9e8
commit cc517ca182
6 changed files with 29 additions and 10 deletions

View File

@ -87,8 +87,8 @@ void CFramework::AimAll()
if (g.g_AimDrawFov)
ImGui::GetBackgroundDrawList()->AddCircle(ToImVec2(Center), g.g_AimFov, AimFovColor, 64);
// 発動キー (既存 Config: 右クリック / 左クリック)
if (!IsKeyDown(g.g_AimKey0) && !IsKeyDown(g.g_AimKey1))
// 発動キー (右クリック / 左クリック / 键盘触发键 F9)
if (!IsKeyDown(g.g_AimKey0) && !IsKeyDown(g.g_AimKey1) && !IsKeyDown(g.g_AimKey2))
return;
// カメラ位置 (ローカル頭部を優先、無ければ origin)

View File

@ -194,7 +194,8 @@ void CFramework::RenderMenu()
ImGui::Text("扫描 : %d 实体 / %d 血量 / %d 跳过", m_diagTotal, m_diagHealth, m_diagSkipped);
ImGui::Text("目标 : %s (距 %0.fpx)", m_diagBestAddr ? "锁定" : "无", m_diagBestDist);
{
ImGui::Text("按键 : %s", (IsKeyDown(g.g_AimKey0) || IsKeyDown(g.g_AimKey1)) ? "按住" : "---");
bool k2 = (GetAsyncKeyState(g.g_AimKey2) & 0x8000) != 0;
ImGui::Text("按键 : %s (右键/左键/F9)", (IsKeyDown(g.g_AimKey0) || IsKeyDown(g.g_AimKey1) || k2) ? "按住" : "---");
}
ImGui::EndChild();

View File

@ -31,16 +31,18 @@ void CFramework::RenderInfo()
StringEx(ImVec2(8.f, 24.f), ImColor(1.f, 1.f, 0.f, 1.f), ImGui::GetFontSize(), diag);
// --- 自瞄实时状态 (关菜单也能看) ---
// Aim = 自瞄开关; M = 方式(MEM内存/MOU鼠标); Key = 触发键是否按住
// Tgt = 是否锁定目标; d = 目标离屏幕中心距离px
// Aim = 自瞄开关; M = 方式(MEM内存/MOU鼠标); Key = 触发键是否按住(含F9)
// Tgt = 是否锁定目标; d = 目标离屏幕中心距离px; Hook/Btn = 鼠标钩子状态
char aim[192]{};
snprintf(aim, sizeof(aim),
"Aim:%s M:%s Key:%s Tgt:%s d=%.0fpx",
"Aim:%s M:%s Key:%s Tgt:%s d=%.0fpx Hook:%s Btn:%lu",
g.g_Aim ? "ON" : "OFF",
g.g_AimMethod == 0 ? "MEM" : "MOU",
(IsKeyDown(g.g_AimKey0) || IsKeyDown(g.g_AimKey1)) ? "HOLD" : "--",
(IsKeyDown(g.g_AimKey0) || IsKeyDown(g.g_AimKey1) || IsKeyDown(g.g_AimKey2)) ? "HOLD" : "--",
m_diagBestAddr ? "LOCK" : "NONE",
m_diagBestDist);
m_diagBestDist,
IsMouseHookInstalled() ? "OK" : "FAIL",
GetMouseHookCount());
StringEx(ImVec2(8.f, 42.f), ImColor(1.f, 0.f, 0.f, 1.f), ImGui::GetFontSize(), aim);
// Crosshair

View File

@ -69,6 +69,7 @@ struct Globals
int g_MenuKey = VK_INSERT;
int g_AimKey0 = VK_RBUTTON;
int g_AimKey1 = VK_LBUTTON;
int g_AimKey2 = VK_F9; // 键盘触发键 (鼠标键检测异常时的替代, 按住触发)
};
extern Globals g;

View File

@ -4,6 +4,7 @@ namespace
{
volatile bool g_mouseL = false; // 左键按下状态 (低级钩子捕获)
volatile bool g_mouseR = false; // 右键按下状态
volatile unsigned long g_mouseEvents = 0; // 钩子捕获事件计数 (诊断用)
HHOOK g_mouseHook = nullptr;
// 低级鼠标钩子回调: 在安装线程的消息循环中触发 (OverlayLoop 的 PeekMessage)
@ -11,6 +12,7 @@ namespace
{
if (nCode >= 0)
{
g_mouseEvents++;
switch (wParam)
{
case WM_LBUTTONDOWN: g_mouseL = true; break;
@ -38,6 +40,16 @@ void RemoveInputHook()
}
}
bool IsMouseHookInstalled()
{
return g_mouseHook != nullptr;
}
unsigned long GetMouseHookCount()
{
return g_mouseEvents;
}
bool IsKeyDown(int vk)
{
// 鼠标键: 钩子状态优先, GetAsyncKeyState 兜底

View File

@ -5,7 +5,10 @@
// 问题: GetAsyncKeyState 在管理员权限/整合包环境下检测不到鼠标按键(左/右键)
// 方案: WH_MOUSE_LL 低级钩子全局捕获鼠标按下/释放, IsKeyDown 优先读钩子状态
// 键盘键仍然走 GetAsyncKeyState (菜单 INSERT 切换已验证有效)
// 若钩子仍无效, 用键盘触发键 (g_AimKey2, 默认 F9) 绕开鼠标键检测
bool IsKeyDown(int vk);
void InstallInputHook();
void RemoveInputHook();
bool IsMouseHookInstalled(); // 钩子是否安装成功 (诊断用)
unsigned long GetMouseHookCount(); // 钩子捕获事件数 (诊断用)