查找固定的任务栏快捷方式的坐标? [英] Find Cordinates of pinned taskbar Shorcuts?

查看:95
本文介绍了查找固定的任务栏快捷方式的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用autohotkey编写脚本.该脚本的目的是更改某人单击任务栏上的程序所执行的操作.例如,如果有人说三次单击任务栏上的IE,它将以专用模式打开.我在下面有一些此代码,我的问题是我试图找到一种自动确定任务栏图标在任务栏上位置的方法,以便程序可以为每次单击设置边界.我尝试在注册表中查找,还尝试从程序中提取图标,然后使用imagesearch在屏幕上搜索它们,但是找不到图标....我能做到这一点吗?

I am writing a script in autohotkey. The purpose of the script is to change the action performed by the program that someone clicks on the taskbar. For Example if someone say triple clicks IE on the taskbar it opens in in private mode. I have some code of this below, my problem is I am trying to find a way to automatically determine the location of the taskbar icons on the taskbar so that the program can set it's bounds for each click. I have tried looking in the registry and I have also tried extracting the icons from the programs and searching for them on screen using imagesearch but it fails to find the icons.... Any way I can accomplish this?

代码

#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"
                }
    }

}

推荐答案

我之前尝试过类似的操作,请告诉我,图标的位置不在注册表中.我记录了单击或移动任务栏图标时发生的每个文件/注册表访问.因此,我只能假定此信息存储在资源管理器进程中.通过在任务栏图标周围移动然后重新启动资源管理器过程,您可以或多或少地证明这一点.任务栏图标位置将被重置.

I've tried similar things before and let me tell you, the locations of the icons are not in the registry. I logged every file/registry access that occurred when clicking or moving a taskbar icon. So I can only assume that this information is stored in the explorer process. You can more or less proof that by moving around the taskbar icons and then restarting the explorer process. The taskbar icon positions will be reset then.

Blauhirn已经指出了我早些时候写的一些解决方法.但这真的很有限...

Blauhirn already pointed to a little workaround that I wrote some time ago. But it's really limited...

不过,正确设置的图像搜索应该可以进行.

A properly set up image search should work though.

  • 找到所有窗口
  • 找到运行每个窗口的过程并从其exe中提取图标
    (甚至更好的方法是直接从窗口中提取图标.)
  • 找出任务栏图标的大小
  • 也许可以使用gdip调整提取图标的大小
  • 然后创建一个特定于任务栏的lbutton热键,该按钮可在任务栏中鼠标周围的较小半径上进行图像搜索.
  • find all windows
  • find the process that runs each window and extract the icon from its exe
    (or even better find a way to extract the icon form the window directly.)
  • find out which size the taskbar icons are
  • maybe resize the extracted icons using gdip
  • then create a taskbar specific lbutton hotkey that does an image search on a small radius around the mouse in the taskbar.

但这需要大量的研究和工作.

But that would take a lot of research and work..

最干净的方法可能是使用外壳钩子.但是利用shell钩子的ahk脚本非常罕见,因此这意味着需要进行更多的研究.

The cleanest thing would probably be to use a shell hook. But ahk scripts that make use of shell hooks are very rare, so that would mean even more research..


我刚刚意识到您正在谈论固定图标.
为此,您可以遍历包含所有固定快捷方式的目录...
只是给您一些想法:
(完全未经测试,最有可能需要对imagesearch进行调整)


I just realized that you are talking about pinned icons in particular.
For that you could loop through the directory that holds all the pinned shortcuts...
Just to give you some idea:
(completely untested and the imagesearch most likely needs adjustment)

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
}

这篇关于查找固定的任务栏快捷方式的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆