首页 > 其他分享 >用热键win+字母激活任务栏上的按钮[ahk]

用热键win+字母激活任务栏上的按钮[ahk]

时间:2023-04-25 13:02:52浏览次数:42  
标签:Return win 热键 Asc Uint ahk ThisLabel FocusButton 96


;bug:热键请自行修改,发现按win+d win+l 等和系统热键冲突,可以改成空格键或Capslock键+字母

; File encoding:  UTF-8

AutoHotkey 版本: 1.0.9.1
操作系统:    Windows XP


脚本说明:Quick task switching with Win+[a,b,...,z]
脚本版本:   v1.0
Timestamp:2012-12-20 14:12:56
*/

;改版by sunwind:
;~ 按win+-显示任务栏上按钮标号
;~ 标号是用字母标识
;~ 按win+字母 切换

;~ 原版:
;Quick task switching with Win+[1,2,...,0]
;Win + 数字键 切换,用 Win - 可能看到任务栏标号,然后再 Win + 数字 切换
;http://www.autohotkey.com/forum/viewtopic.php?t=41542&highlight=taskbar+order+switch
#SingleInstance
#WinActivateForce
Build_hWndArray(26)
Loop  %g_bundleCount%
  {
    sym:=Chr(A_Index+96)
    Hotkey, #%sym%, %sym%
  }
Return
a:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
b:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
c:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
d:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
e:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
f:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
g:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
h:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
i:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
j:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
k:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
l:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
m:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
n:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
o:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
p:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
q:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
r:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
s:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
t:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
u:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
v:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
w:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
x:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
y:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
z:
  n:=Asc(A_ThisLabel)-96
  FocusButton(n)
Return
;WIN+- shows button numbers as tooltips.

#-::
#NumpadSub::
  ShowToolTips()
  SetTimer, RemoveToolTips, -1000
Return

RemoveToolTips:
  Loop, 12
      ToolTip,,,,%A_Index%
Return

ShowToolTips()
  {
    global g_bundleCount

    CoordMode, ToolTip, Screen
    Loop, %g_bundleCount%
      {
        ;~ If A_Index < 5
        ;~ continue

        x := g_xs%A_Index%
        y := g_ys%A_Index%
        ;~ If A_Index = 10
        ;~ text = 0
        ;~ Else
        ;~ text = %A_Index%
        text:=Chr(A_Index+96)
        ToolTip, %text%, %x%, %y%, %A_Index%
      }
  }

Add_hWndToArray(gi, hWnd)
  {
    global
    g_bundleSize%gi% := g_bundleSize%gi% + 1
    local wi := g_bundleSize%gi%
    g_hWnd%gi%_%wi% := hWnd
  }

AddBundle(gi)
  {
    global
    g_bundleSize%gi% := 0
  }

BundleSize(gi)
  {
    global
    Return g_bundleSize%gi%
  }

Get_hWndFromArray(gi, wi)
  {
    global
    Return g_hWnd%gi%_%wi%
  }

SetButtonTopLeftLoc(gi, x, y)
  {
    global
    g_xs%gi% := x
    g_ys%gi% := y
  }

Build_hWndArray(maxBundleCount)
  {
    global g_bundleCount

    WinGet,	pidTaskbar, PID, ahk_class Shell_TrayWnd
    hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
    pProc := DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
    idxTB := GetTaskSwBar()
    SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_ButtonCount
    ButtonCount := ErrorLevel

    g_bundleCount := 0

    Loop, %ButtonCount%
      {
        SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_GETButton

        VarSetCapacity(btn, 32, 0)
        DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)

        idn	:= NumGet(btn, 4)
        Statyle := NumGet(btn, 8, "Char")
        dwData := NumGet(btn, 12)
        If Not dwData
            dwData := NumGet(btn, 16, "int64")

        DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "int64P", hWnd:=0, "Uint", NumGet(btn,12) ? 4:8, "Uint", 0)

        If Not hWnd ; Group Button, indicates the start of a Group
          {
            If g_bundleCount >= %maxBundleCount%
                Break
            Hidden := Statyle & 0x08 ; TBSTATE_Hidden
            If Not Hidden
              {
                grpCollapsed := true
                g_bundleCount := g_bundleCount + 1
                AddBundle(g_bundleCount)

                GetTaskbarButtonTopLeft(idn, x, y)
                SetButtonTopLeftLoc(g_bundleCount, x, y)
              }
            Else
                grpCollapsed := false
          }
        Else ; actual window Button
          {
            If grpCollapsed
              {
                Add_hWndToArray(g_bundleCount, hWnd)
              }
            Else
              {
                g_bundleCount := g_bundleCount + 1
                AddBundle(g_bundleCount)
                Add_hWndToArray(g_bundleCount, hWnd)
                GetTaskbarButtonTopLeft(idn, x, y)
                SetButtonTopLeftLoc(g_bundleCount, x, y)
              }
          }
      }

    DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
    DllCall("CloseHandle", "Uint", hProc)
  }

FocusButton(n)
  {
    global g_bundleCount

    ; these static variables can become inaccurate if windows are created or closed
    ; inbetween pressing of hotkeys, but in practice, we can safely ignore the
    ; inaccuracy
    static prevBundleIndex := 0
    static prevWindowIndex := 0

    Build_hWndArray(n)

    If (g_bundleCount >= n)
      {
        bundleSize := BundleSize(n)

        If n = %prevBundleIndex%
            windowIndex := Mod(prevWindowIndex, bundleSize) + 1
        Else
            windowIndex := 1

        hWnd := Get_hWndFromArray(n, windowIndex)

        If bundleSize > 1 ; cycle through windows in the same bundle
            WinActivate, ahk_id %hWnd%
        Else ; Single-window bundle; Toggles Between activating (restoring) and minimizing the window
            IfWinActive, ahk_id %hWnd%
                WinMinimize, ahk_id %hWnd%
            Else
                WinActivate, ahk_id %hWnd%
        prevBundleIndex := n
        prevWindowIndex := windowIndex
      }
  }

GetTaskSwBar()
  {
    ControlGet, hParent, hWnd,, MSTaskSwWClass1 , ahk_class Shell_TrayWnd
    ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
    Loop
      {
        ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
        If Not hWnd
            Break
        Else If hWnd = %hChild%
          {
            idxTB := A_Index
            Break
          }
      }
    Return	idxTB
  }

GetTaskbarButtonTopLeft(id, ByRef x, ByRef y)
  {
    idxTB := GetTaskSwBar()
    WinGet,	pidTaskbar, PID, ahk_class Shell_TrayWnd
    hProc := DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
    pProc := DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
    idxTB := GetTaskSwBar()

    SendMessage, 0x433, id, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_GETRECT
    ;IfEqual, ErrorLevel, 0, return "Err: can't get rect"

    VarSetCapacity(rect, 32, 0)
    DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &rect, "Uint", 32, "Uint", 0)

    DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
    DllCall("CloseHandle", "Uint", hProc)

    ControlGet, hWnd, hWnd,, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd
    WinGetPos, x, y, w, h, ahk_id %hWnd%

    left := NumGet(rect, 0)
    top := NumGet(rect, 4)
    Right := NumGet(rect, 8)
    Bottom := NumGet(rect, 12)

    x := x + left
    y := y + top
  }



标签:Return,win,热键,Asc,Uint,ahk,ThisLabel,FocusButton,96
From: https://blog.51cto.com/u_15408625/6223783

相关文章

  • [ahk]右键菜单打开文件所在文件夹(快捷方式也适用)
    功能:能打开文件所在路径并定位到文件上,能正确解析lnk所指文件的目录。 copypath.ahk 文件如下: #NoTrayIconClipboard=%1% openpath.ahk文件如下:#NoTrayIconClipboard=%1%Run,%"Explorer.exe/select,"Clipboard说明一:剪贴板内容被置为文件路径了。说明二:需要注册到......
  • Replacing Windows Notepad with Notepad2 4.1.24 (or newer)
    ReplacingWindowsNotepadwithNotepad24.1.24(ornewer)Asofversion4.1.24,theofficialreleaseofNotepad2supportsthismethodforreplacingWindowsNotepad,sothestepsoutlinedabovewillworkfine.However,there'snosupporttoperformthe......
  • [AHK]热键获取TC当前的路径
    原创部分:热键alt+shif+c复制当前tc窗口中的路径。#IfWinActiveahk_classTTOTAL_CMD!+c::PostMessage1075,2029,0,,ahk_classTTOTAL_CMD;复制完整路径return#IfWinActive2010年04月11日星期日17:07一故事的开始,寻找TotalCommander(以下简称TC)的快捷键--“在下已经严重鼠......
  • 用自己指定的模板创建ahk脚本
    在windows右键弹出菜单的新建菜单中加入“AutoHotkey脚本” 1.首先写好模板文件,随便保存在一个地方,比如我是“X:\AutoHotkey\AutoHotkey\SHELLNEW\Template.ahk”;2.打开注册表(regedit),找到[HKEY_CLASSES_ROOT]->[.ahk](没有的话,自己新建项.ahk);3.在[.ahk]下新建项[ShellN......
  • win环境基于docker搭建zookeeper伪集群
    创建路径:D:\Docker\zk-cluster在此路径下创建配置文件:docker-compose.ymlversion:'2'networks:zk-net:name:zk-netservices:zoo1:image:zookeeperrestart:alwayscontainer_name:zoo1ports:-"21......
  • windows环境下emacs的python简单配置
    首先参考了上一篇《emacs极简配置》,我的想法是打开兼容vim的viper到5级,然后一些基本的字体设定,然后如何执行python文件的一个全过程方法。1、先打开emacs,如果忘了怎么用了,看一下自带的教程,还是中文的,超级方便。2、学完后,键入C-xC-f并按~,这样就会打开默认的配置文件所在的目录......
  • [ahk]获取文华财经全自动运行模组信号记录
    #Persistent#SingleInstanceForceDetectHiddenWindows,OnControl:="SysListView323"WinTitle:="全自动运行模组ahk_class#32770"WinText:="List1"ControlClick,Button26,%WinTitle% ControlGet,......
  • [AHK]倒计时牌(高考还有多少天这类的)
    ;DaysLeft.ahk;Authorsnwind/*[config]DateTarget=20151204000000DateFrom=20151106000000*/;~#SingleInstance,force;~ListLines,OnFormatTime,today,,yyyyMMddIniRead,DateTarget,%A_ScriptFullPath%,config,DateTarge......
  • [ahk]读取excel文件实例
    EXCEL内容如下:AutoHotkey代码如下:#Persistent#SingleInstance,force;2015年1月4日;sunwind;读取excel实例excel:=ComObjActive("Excel.Application")filepath:=A_ScriptDir."\循环读取.xlsx";自动运行、初始化Runnotepadxls:=Check(fil......
  • rust交叉编译配置:windows上编译linux可执行程序
    rust交叉编译配置:windows上编译linux可执行程序简述交叉编译大概指在在一种计算机环境中运行的编译程序,能编译出在另外一种环境下运行的代码.本次,我们配置的是在windows上编译出在linux上运行的rust可执行程序.我们在安装rust之后,默认会安装跟机器环境搭配的编译相关工具.......