Find Cordinates from Shorcuts pinned to taskbar?

I am writing a script in autohotkey. The purpose of a script is to change the action a program takes that someone clicks on the taskbar. For example, if someone talks about triple clicks of IE on the taskbar, it opens in private mode. I have the code for this below, my problem is that I am trying to find a way to automatically locate the taskbar icons on the taskbar so that the program can set its borders on every click. I tried searching in the registry and I also tried to extract icons from programs and search for them on the screen using image search, but it cannot find icons .... Is there anyway I can do this?

CODE

#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


source to share


1 answer


I've tried similar things before and let me tell you that the location of the icons is missing from the registry. I logged every file / registry access that occurred when clicking or moving an icon on the taskbar. So I can only assume that this information is stored in the explorer process. You can more or less prove that by moving the icons on the taskbar and restarting the explorer process. The system tray icons will be reset.

Blauchirn has already pointed out a small workaround that I wrote a while ago. But it's really limited ...

A properly configured image search should work.

  • find all windows
  • find the process that launches each window and fetches the icon from its exe
    (or even better, find a way to extract the icon from the window directly.)
  • find out what size the icons on the taskbar are
  • it is possible to resize the extracted icons with gdip
  • then create a dedicated hotkey on the taskbar that searches for images in a small radius around the mouse on the taskbar.


But it will take a lot of research and work.

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

Edit:
I just realized that you are talking about pinned icons in particular.
To do this, you can scroll through the directory containing all pinned shortcuts ...
Just to give you some idea:
(completely untested, and the image search most likely needs adjusting)

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
}

      

+1


source







All Articles