我正在用autohotkey编写一个脚本。该脚本的目的是更改用户在任务栏上单击的程序执行的操作。例如,如果有人说三重点击任务栏上的IE,则会以私人模式打开。我有一些下面的代码,我的问题是我试图找到一种方法来自动确定任务栏上任务栏图标的位置,以便程序可以为每次点击设置它的界限。我已经尝试在注册表中查找,我也尝试从程序中提取图标并使用imagesearch在屏幕上搜索它们,但它无法找到图标....我可以用任何方式完成此操作吗?
代码
#NoEnv ; Recommended for performance and compatibility with future
AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
CoordMode, Mouse, Screen
Time = 500
~Lbutton::
;if there is a double left click
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < Time)
{
Count ++
}
Else
{
Count = 1
}
SetTimer, Handler, %Time%
return
Handler:
SetTimer, Handler, Off
IfEqual, Count, 2
{
If (Mouse_y > 1040)
{
If (Mouse_x > 50) and (Mouse_x < 98) ;over my explorer icon
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Internet Explorer.lnk"
}
If (Mouse_x > 99) and (Mouse_x < 147 ) ; over powershell ise
{
Run, explorer.exe
}
If (Mouse_x > 148) and (Mouse_x < 196 ) ; over chrome
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\outlook 2013.lnk"
}
If (Mouse_x > 197) and (Mouse_x < 245) ; over ie
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Active Directory Users and Computers.lnk"
}
If (Mouse_x > 246) and (Mouse_x < 294 ) ; over vs 2015
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\DHCP.lnk"
}
If (Mouse_x > 295) and (Mouse_x < 343 ) ; over pusbullet
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\DNS.lnk"
}
}
}
IfEqual, Count, 3
{
If (Mouse_y > 1040)
{
If (Mouse_x > 50) and (Mouse_x < 98) ;over my explorer icon
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Internet Explorer.lnk" -private
}
If (Mouse_x > 99) and (Mouse_x < 147 ) ; over powershell ise
{
Run, explorer.exe
}
If (Mouse_x > 148) and (Mouse_x < 196 ) ; over chrome
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\outlook 2013.lnk"
}
If (Mouse_x > 197) and (Mouse_x < 245) ; over ie
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Active Directory Users and Computers.lnk"
}
If (Mouse_x > 246) and (Mouse_x < 294 ) ; over vs 2015
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\DHCP.lnk"
}
If (Mouse_x > 295) and (Mouse_x < 343 ) ; over pusbullet
{
Run, "%A_AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\DNS.lnk"
}
}
}
答案 0 :(得分:1)
之前我尝试过类似的事情让我告诉你,图标的位置不在注册表中。我记录了单击或移动任务栏图标时发生的每个文件/注册表访问。所以我只能假设这些信息存储在资源管理器进程中。您可以通过移动任务栏图标然后重新启动资源管理器进程来或多或少地证明这一点。然后将重置任务栏图标位置。
Blauhirn已经指出了我前段时间写过的一些解决方法。但它确实有限......
正确设置图像搜索应该可以正常工作。
但这需要大量的研究和工作......
最干净的事情可能是使用shell钩子。但是使用shell钩子的ahk脚本是非常罕见的,所以这意味着更多的研究..
编辑:
我刚才意识到你正在谈论固定的图标
为此,您可以遍历包含所有固定快捷方式的目录...
只是为了给你一些想法:
(完全未经测试且图像搜索最有可能需要调整)
CoordMode, Mouse, Screen
~LButton::
If (A_TimeSincePriorHotkey<400) and (A_PriorHotkey="~LButton") {
WinGetPos, taskBarX, taskBarY, taskBarW, taskBarH, ahk_class Shell_TrayWnd
MouseGetPos, mouseX, mouseY
If (mouseX >= taskBarX && mouseY >= taskBarY && mouseX <= taskBarX+taskBarW && mouseY <= taskBarY+taskBarH)
OnDoubleClickTaskbar(mouseX, mouseY, taskBarX, taskBarY, taskBarW, taskBarH)
}
Return
OnDoubleClickTaskbar(mX,mY,tX,tY,tH,tW) {
iconSize := GetTaskbarIconSize()
pinnedIcons := GetPinnedIcons()
Loop % pinnedIcons.MaxIndex() {
ico := pinnedIcons[A_Index]
ImageSearch, foundX, foundY, tX, tY, tW, tH, % "*Icon" ico.index " " "*20" " " "*w" iconSize " " "*h" iconSize " " ico.icon
If (!ErrorLevel)
MsgBox, % "Icon found: " ico.icon "," ico.index " at " "x" foundX " y" foundY
Else
MsgBox, % "Icon not found: " ico.icon "," ico.index
}
}
GetPinnedIcons() {
pinnedIcons := []
Loop, % A_AppData "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*.lnk"
{
FileGetShortcut, % A_LoopFileFullPath, shortCutTarget,,,, icon, iconIndex
pinnedIcons[A_Index] := {"icon":icon, "index": iconIndex}
}
Return pinnedIcons
}
GetTaskbarIconSize() {
Return 32
}