From e831a7416ba2dd1f342e710c6048c8fa97291d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 1 Dec 2020 23:18:35 +0100 Subject: Switch to Windows 7 --- !tt.windowselect.ahk | 202 +++++++++++++++++++++++++++++++++++++++++++++++ scripts.ahk | 2 +- tt.jump.ahk | 9 ++- tt.programs.explorer.ahk | 59 ++++---------- tt.volume.ahk | 17 ++-- tt.windowselect.ahk | 202 ----------------------------------------------- 6 files changed, 232 insertions(+), 259 deletions(-) create mode 100644 !tt.windowselect.ahk delete mode 100644 tt.windowselect.ahk diff --git a/!tt.windowselect.ahk b/!tt.windowselect.ahk new file mode 100644 index 0000000..0914004 --- /dev/null +++ b/!tt.windowselect.ahk @@ -0,0 +1,202 @@ +;; Select window by number ---------------------------------------------------- + +;; -> body + +#1::FocusButton(1) +#2::FocusButton(2) +#3::FocusButton(3) +#4::FocusButton(4) +#5::FocusButton(5) +#6::FocusButton(6) +#7::FocusButton(7) +#8::FocusButton(8) +#9::FocusButton(9) +#0::FocusButton(10) + +;; -> library + +; https://code.google.com/archive/p/activatebynum/ + +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 +} diff --git a/scripts.ahk b/scripts.ahk index 45d4cbe..f022e7b 100644 --- a/scripts.ahk +++ b/scripts.ahk @@ -67,7 +67,7 @@ return ^F12 Up:: Sleep, 600 -Run, %A_WinDir%\system32\ssstars.scr /s ; start screen saver +Run, %A_WinDir%\system32\Mystify.scr /s ; start screen saver return ; Library --------------------------------------------------------------------- diff --git a/tt.jump.ahk b/tt.jump.ahk index 35b6022..31fe3f7 100644 --- a/tt.jump.ahk +++ b/tt.jump.ahk @@ -3,10 +3,11 @@ JumpPaths := { s: env("Sync") , w: env("Sync") "\Projekt\john.ankarstrom.se\htdocs" , g: env("Sync") "\Projekt\git" - , e: env("Personal") - , d: env("Personal") "\Downloads" - , m: env("Personal") "\MP3" - , p: env("Personal") "\My Pictures" } + , u: env("UserProfile") + , e: env("UserProfile") "\Documents" + , d: env("UserProfile") "\Downloads" + , m: env("UserProfile") "\Music" + , p: env("UserProfile") "\Pictures" } ;; -> body diff --git a/tt.programs.explorer.ahk b/tt.programs.explorer.ahk index 0d31034..db07380 100644 --- a/tt.programs.explorer.ahk +++ b/tt.programs.explorer.ahk @@ -50,12 +50,7 @@ WinWait, ahk_class ConsoleWindowClass SendInput, % "cd " path "{Return}" return -; Create new folder/file - -^+n:: -FileCreateDir, % ExplorerPath() "\New Folder" -SendInput, {F5}New Folder{F2} -return +; Create new file ^!n:: FileAppend,, % ExplorerPath() "\New Text Document.txt" @@ -129,35 +124,24 @@ Loop, % win PostMessage, 0x111, 41504,,, % "ahk_id " win%A_Index% ; refresh return -; Sort and display options - -^q::ExplorerFolderView("name") -^w::ExplorerFolderView("modified") -^e::ExplorerFolderView("type") -^t::ExplorerFolderView("created") -^g::ExplorerFolderView("groups") -^s::ExplorerFolderView("tiles") -^d::ExplorerFolderView("icons") -^+d::ExplorerFolderView("thumbnails") -^f::ExplorerFolderView("details") -^+f::ExplorerFolderView("list") - -^!q::ExplorerFolderView("name", true) -^!w::ExplorerFolderView("modified", true) -^!e::ExplorerFolderView("type", true) -^!t::ExplorerFolderView("created", true) -^!g::ExplorerFolderView("groups", true) -^!s::ExplorerFolderView("tiles", true) -^!d::ExplorerFolderView("icons", true) -^!+d::ExplorerFolderView("thumbnails", true) -^!f::ExplorerFolderView("details", true) -^!+f::ExplorerFolderView("list", true) +; Sort and display options (Windows XP) + +;^q::ExplorerFolderView("name") +;^w::ExplorerFolderView("modified") +;^e::ExplorerFolderView("type") +;^t::ExplorerFolderView("created") +;^g::ExplorerFolderView("groups") +;^s::ExplorerFolderView("tiles") +;^d::ExplorerFolderView("icons") +;^+d::ExplorerFolderView("thumbnails") +;^f::ExplorerFolderView("details") +;^+f::ExplorerFolderView("list") #IfWinActive ;; -> library -ExplorerFolderView(view, children := false) +ExplorerFolderView(view) { if (view = "name") n := {m: 30210, d: -1} @@ -180,20 +164,8 @@ ExplorerFolderView(view, children := false) else if (view = "list") n := {m: 28715, d: 3} - PostMessage, 0x111, % n.m, 0,, A ; change current folder + PostMessage, 0x111, % n.m, 0,, A return - if (not children or m.d = -1) - return - - old := A_BatchLines - SetBatchLines, -1 - - Loop, Files, % ExplorerPath() "\*", D - { - MsgBox, % A_LoopFileFullPath - } - - SetBatchLines, % old } ;; Git hotkeys ---------------------------------------------------------------- @@ -231,6 +203,7 @@ basename(s) !c::Run, % "cmd /c cd "qp()" & git commit & pause" !+c::Run, % "cmd /c cd "qp()" & git commit --amend & pause" !^c::Run, % "cmd /c cd "qp()" & git commit -a & pause" +!^+c::Run, % "cmd /c cd "qp()" & git commit -a --amend & pause" !p::Run, % "cmd /c cd "qp()" & git push & pause" !s::Run, % "cmd /c cd "qp()" & git status & pause" diff --git a/tt.volume.ahk b/tt.volume.ahk index e01be7d..5946469 100644 --- a/tt.volume.ahk +++ b/tt.volume.ahk @@ -13,15 +13,14 @@ RAlt & F5::SetVolume(GetKeyState("Shift") ? -2 : -1) SetVolume(n) { - SoundGet, w, WAVE - SoundSet, 15 - w := round(w) + n - if (w > 100) - w := 100 - if (w < 0) - w := 0 - SoundSet, %w%, WAVE - OSD(w) + SoundGet, s + s := round(s) + n + if (s > 100) + s := 100 + if (s < 0) + s := 0 + SoundSet, %s% + OSD(s) } /* diff --git a/tt.windowselect.ahk b/tt.windowselect.ahk deleted file mode 100644 index 0914004..0000000 --- a/tt.windowselect.ahk +++ /dev/null @@ -1,202 +0,0 @@ -;; Select window by number ---------------------------------------------------- - -;; -> body - -#1::FocusButton(1) -#2::FocusButton(2) -#3::FocusButton(3) -#4::FocusButton(4) -#5::FocusButton(5) -#6::FocusButton(6) -#7::FocusButton(7) -#8::FocusButton(8) -#9::FocusButton(9) -#0::FocusButton(10) - -;; -> library - -; https://code.google.com/archive/p/activatebynum/ - -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 -} -- cgit v1.2.3