使用方法

环境声明


使用方法

方法1:安装AutoHotKey v2.0后,将下方代码保存为.ahk格式,双击运行后使用对应的快捷键触发

方法2:使用.ahk编译后的.exe文件,双击运行后使用对应的快捷键触发,该方法不需要安装AutoHotKey v2.0环境就能使用


编译方法

如果需要自己编译可以使用下面的方法

右击.ahk文件,选择Compile Script(GUI),点击Convert,就会生成一个.exe的可执行文件

image-20230820220505135


自启动

每次运行时都需要先执行脚本,可以将脚本或程序添加到系统自启动中

Win + R打开运行,输入shell:startup,将.ahk.exe文件复制到该目录下即可

image-20230820220141846


效果

20230820_221106


快捷键触发

快捷键Alt + Q隐藏或显示桌面图标

如果需要修改快捷键则参考https://zhuanlan.zhihu.com/p/348680863

以下代码引用至https://blog.csdn.net/qq_43442524/article/details/103744613

编译后的可以执行文件下载 -> ahk_1.exe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
!q::
HideOrShowDesktopIcons()
return

HideOrShowDesktopIcons()
{
ControlGet, class, Hwnd,, SysListView321, ahk_class Progman
If class =
ControlGet, class, Hwnd,, SysListView321, ahk_class WorkerW

If DllCall("IsWindowVisible", UInt,class)
WinHide, ahk_id %class%
Else
WinShow, ahk_id %class%
}


双击鼠标触发

双击鼠标左键隐藏或显示桌面图标

以下代码引用至https://chuiyugin.github.io/2022/12/25/Autohotkey/

编译后的可以执行文件下载 -> ahk_2.exe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#If IsDesktopUnderMouse()
~LButton::
LButton_presses++
if (LButton_presses=2)
if (!IsObject(GetDesktopIconUnderMouse()) or DesktopIconsIsShow=0)
DesktopIconsIsShow:=HideOrShowDesktopIcons()
SetTimer, KeyLButton, -300
return

KeyLButton:
LButton_presses := 0
return

IsDesktopUnderMouse()
{
MouseGetPos, , , OutputVarWin
WinGetClass, OutputVarClass, % "ahk_id" OutputVarWin
if (OutputVarClass="WorkerW" or OutputVarClass="Progman")
return, 1
else
return, 0
}

HideOrShowDesktopIcons()
{
ControlGet, OutputVarHwnd, Hwnd,, SysListView321, ahk_class WorkerW
if (OutputVarHwnd="")
ControlGet, OutputVarHwnd, Hwnd,, SysListView321, ahk_class Progman

if (DllCall("IsWindowVisible", UInt, OutputVarHwnd))
{
WinHide, ahk_id %OutputVarHwnd%
return, 0
}
else
{
WinShow, ahk_id %OutputVarHwnd%
return, 1
}
}
#If

GetDesktopIconUnderMouse() {
static MEM_COMMIT := 0x1000, MEM_RELEASE := 0x8000, PAGE_ReadWRITE := 0x04
, PROCESS_VM_OPERATION := 0x0008, PROCESS_VM_READ := 0x0010
, LVM_GETITEMCOUNT := 0x1004, LVM_GETITEMRECT := 0x100E

Icon := ""
MouseGetPos, x, y, hwnd
if not (hwnd = WinExist("ahk_class Progman") || hwnd = WinExist("ahk_class WorkerW"))
return
ControlGet, hwnd, HWND, , SysListView321
if not WinExist("ahk_id" hwnd)
return
WinGet, pid, PID
if (hProcess := DllCall("OpenProcess" , "UInt", Process_VM_OPERATION|Process_VM_Read, "Int", false, "UInt", pid)) {
VarSetCapacity(iCoord, 16)
SendMessage, %LVM_GETITEMCOUNT%, 0, 0
loop, %ErrorLevel% {
pItemCoord := DllCall("VirtualAllocEx", "Ptr", hProcess, "Ptr", 0, "UInt", 16, "UInt", MEM_COMMIT, "UInt", PAGE_ReadWRITE)
SendMessage, %LVM_GETITEMRECT%, % A_Index-1, %pItemCoord%
DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", pItemCoord, "Ptr", &iCoord, "UInt", 16, "UInt", 0)
DllCall("VirtualFreeEx", "Ptr", hProcess, "Ptr", pItemCoord, "UInt", 0, "UInt", MEM_RELEASE)
left := NumGet(iCoord, 0, "Int")
top := NumGet(iCoord, 4, "Int")
Right := NumGet(iCoord, 8, "Int")
bottom := NumGet(iCoord, 12, "Int")
if (left < x and x < Right and top < y and y < bottom) {
ControlGet, list, List
RegExMatch(StrSplit(list, "`n")[A_Index], "O)(.*)\t(.*)\t(.*)\t(.*)", Match)
Icon := {left:left, top:top, Right:Right, bottom:bottom
, name:Match[1], size:Match[2], type:Match[3]
; Delete extraneous date characters (https://goo.gl/pMw6AM):
; - Unicode LTR (Left-to-Right) mark (0x200E = 8206)
; - Unicode RTL (Right-to-Left) mark (0x200F = 8207)
, date:RegExReplace(Match[4], A_IsUnicode ? "[\x{200E}-\x{200F}]" : "\?")}
break
}
}
DllCall("CloseHandle", "Ptr", hProcess)
}
return Icon
}


合并触发

使用快捷键Alt + Q双击鼠标左键都可以隐藏或显示桌面图标,以下代码使用上述两个代码加上AssistantAI合并而成

编译后的可以执行文件下载 -> ahk_3.exe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#If IsDesktopUnderMouse()
~LButton::
LButton_presses++
if (LButton_presses = 2)
if (!IsObject(GetDesktopIconUnderMouse()) or DesktopIconsIsShow = 0)
DesktopIconsIsShow := HideOrShowDesktopIcons()
SetTimer, KeyLButton, -300
return

KeyLButton:
LButton_presses := 0
return

!q::
HideOrShowDesktopIcons()
return

IsDesktopUnderMouse()
{
MouseGetPos, , , OutputVarWin
WinGetClass, OutputVarClass, % "ahk_id" OutputVarWin
if (OutputVarClass = "WorkerW" or OutputVarClass = "Progman")
return 1
else
return 0
}

HideOrShowDesktopIcons()
{
ControlGet, class, Hwnd,, SysListView321, ahk_class Progman
If class =
ControlGet, class, Hwnd,, SysListView321, ahk_class WorkerW

If DllCall("IsWindowVisible", UInt,class)
WinHide, ahk_id %class%
Else
WinShow, ahk_id %class%
}

GetDesktopIconUnderMouse()
{
static MEM_COMMIT := 0x1000, MEM_RELEASE := 0x8000, PAGE_ReadWRITE := 0x04
, PROCESS_VM_OPERATION := 0x0008, PROCESS_VM_READ := 0x0010
, LVM_GETITEMCOUNT := 0x1004, LVM_GETITEMRECT := 0x100E

Icon := ""
MouseGetPos, x, y, hwnd
if not (hwnd = WinExist("ahk_class Progman") || hwnd = WinExist("ahk_class WorkerW"))
return
ControlGet, hwnd, HWND, , SysListView321
if not WinExist("ahk_id" hwnd)
return
WinGet, pid, PID
if (hProcess := DllCall("OpenProcess" , "UInt", Process_VM_OPERATION|Process_VM_Read, "Int", false, "UInt", pid)) {
VarSetCapacity(iCoord, 16)
SendMessage, %LVM_GETITEMCOUNT%, 0, 0
loop, %ErrorLevel% {
pItemCoord := DllCall("VirtualAllocEx", "Ptr", hProcess, "Ptr", 0, "UInt", 16, "UInt", MEM_COMMIT, "UInt", PAGE_ReadWRITE)
SendMessage, %LVM_GETITEMRECT%, % A_Index-1, %pItemCoord%
DllCall("ReadProcessMemory", "Ptr", hProcess, "Ptr", pItemCoord, "Ptr", &iCoord, "UInt", 16, "UInt", 0)
DllCall("VirtualFreeEx", "Ptr", hProcess, "Ptr", pItemCoord, "UInt", 0, "UInt", MEM_RELEASE)
left := NumGet(iCoord, 0, "Int")
top := NumGet(iCoord, 4, "Int")
Right := NumGet(iCoord, 8, "Int")
bottom := NumGet(iCoord, 12, "Int")
if (left < x and x < Right and top < y and y < bottom) {
ControlGet, list, List
RegExMatch(StrSplit(list, "`n")[A_Index], "O)(.*)\t(.*)\t(.*)\t(.*)", Match)
Icon := {left:left, top:top, Right:Right, bottom:bottom
, name:Match[1], size:Match[2], type:Match[3]
; Delete extraneous date characters (https://goo.gl/pMw6AM):
; - Unicode LTR (Left-to-Right) mark (0x200E = 8206)
; - Unicode RTL (Right-to-Left) mark (0x200F = 8207)
, date:RegExReplace(Match[4], A_IsUnicode ? "[\x{200E}-\x{200F}]" : "\?")}
break
}
}
DllCall("CloseHandle", "Ptr", hProcess)
}
return Icon
}