Skip to content

Instantly share code, notes, and snippets.

@kaixinol
Created May 23, 2026 05:29
Show Gist options
  • Select an option

  • Save kaixinol/96099ab479445a486f6a928278763efd to your computer and use it in GitHub Desktop.

Select an option

Save kaixinol/96099ab479445a486f6a928278763efd to your computer and use it in GitHub Desktop.
fix pointer when using big cursor
#Requires AutoHotkey v2.0
#SingleInstance Force
; --- 配置区域 ---
HideDelay := 400 ; 闲置多久隐藏(单位:毫秒)
ActiveCheck := 100 ; 鼠标活动时的检测频率
HiddenCheck := 200 ; 鼠标隐藏后的检测频率
; ----------------
IsScriptEnabled := false ; 默认关闭状态
MouseHidden := false
; 重新请回高效的全局空白光标
BlankCursor := DllCall("CreateCursor", "Ptr", 0, "Int", 0, "Int", 0, "Int", 32, "Int", 32,
"Ptr", Buffer(128, 0xFF), "Ptr", Buffer(128, 0), "Ptr")
; 退出时完美恢复
OnExit((*) => SystemCursor(1))
if (IsScriptEnabled) {
SetTimer(CheckMouse, ActiveCheck)
}
; --- Ctrl + Alt 开关热键 ---
^Alt:: {
global IsScriptEnabled, MouseHidden
IsScriptEnabled := !IsScriptEnabled
if (IsScriptEnabled) {
SetTimer(CheckMouse, ActiveCheck)
ShowStatusTip("鼠标自动隐藏:已开启")
} else {
SetTimer(CheckMouse, 0)
if (MouseHidden) {
SystemCursor(1)
MouseHidden := false
}
ShowStatusTip("鼠标自动隐藏:已禁用")
}
}
ShowStatusTip(Text) {
ToolTip(Text)
SetTimer(() => ToolTip(), -1500)
}
; ------------------------------
CheckMouse() {
global MouseHidden, IsScriptEnabled
if (!IsScriptEnabled) {
if (MouseHidden) {
SystemCursor(1)
MouseHidden := false
}
return
}
; 核心逻辑:只要不是输入框(IBeam),且到了闲置时间,就隐藏
if (A_Cursor != "IBeam" && A_TimeIdleMouse >= HideDelay) {
if (!MouseHidden) {
SystemCursor(0) ; 全局隐藏
MouseHidden := true
SetTimer(, HiddenCheck)
}
}
; 鼠标在动,或者是输入框,就立刻恢复显示
else {
if (MouseHidden) {
SystemCursor(1) ; 全局恢复
MouseHidden := false
SetTimer(, ActiveCheck)
}
}
}
; 💡 核心改变:用区间循环代替大段数字枚举,既干净又100%全局有效!
SystemCursor(OnOff) {
global BlankCursor
if (OnOff = 0) {
; 遍历 Windows 光标的两个连续 ID 区间(包含了问号 32651)
for range in [[32512, 32516], [32640, 32651]] {
loop range[2] - range[1] + 1 {
currentID := range[1] + A_Index - 1
hCursor := DllCall("CopyImage", "Ptr", BlankCursor, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0, "Ptr")
DllCall("SetSystemCursor", "Ptr", hCursor, "Int", currentID)
}
}
} else {
; 一键恢复 Windows 默认指针方案
DllCall("SystemParametersInfo", "UInt", 0x57, "UInt", 0, "Ptr", 0, "UInt", 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment