Skip to content

Instantly share code, notes, and snippets.

@jerrylususu
Last active December 3, 2023 04:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerrylususu/ca434b7c34c77968ceecd4b735af1fcf to your computer and use it in GitHub Desktop.
Save jerrylususu/ca434b7c34c77968ceecd4b735af1fcf to your computer and use it in GitHub Desktop.
Utils.ahk
; ====== IMPORTANT ======
; If you're using Windows with locale zh-CN, use **GBK** encoding, not UTF8
; Otherwise the notepad save script will not work!
; ====== IMPORTANT ======
#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.
; 【右Ctrl+方向键】执行【Home/End/PgUp/PgDn】
; https://meta.appinn.net/t/home-end-pgup-pgdn/17801
>^Left::
SendInput, {Home}
Return
>^Right::
SendInput, {End}
Return
>^Up::
SendInput, {PgUp}
Return
>^Down::
SendInput, {PgDn}
Return
; Win+C: Open a new cmd window
#C::
Run, Notepad.exe
Return
; Win+N: Open a new TED Notepad window
#N::
Run, C:\Program Files (x86)\TED Notepad\TedNPad.exe
Return
; Win+V when in cmd: direct copy
#IfWinActive ahk_class ConsoleWindowClass
^V::
SendInput {Raw}%clipboard%
return
#IfWinActive
;https://autohotkey.com/board/topic/148619-set-window-always-on-top-and-change-transparency/
global WindowTitle := "Exolesco - Twitch" ;Default window name
global Transparency := 255
refresh()
{
ifWinActive, %WindowTitle%
{
Winset, Transparent, %Transparency%, %WindowTitle%
}
}
!w:: ;Alt+W: Transparency down
if Transparency > 30
{
Transparency := Transparency - 50
} else {
Transparency := 30
}
refresh()
return
!q:: ;Alt+Q: Turn transparency up
if Transparency < 255
{
Transparency := Transparency + 50
} else {
Transparency := 255
}
refresh()
return
; Alt+T: set current window on top
!T:: Winset, Alwaysontop, , A
; http://blog.sachleen.com/posts/1370369043/snapping-windows-vertically-on-portrait-display/
; dir 0 = top part
; dir 1 = bottom part
; size 0 = half of screen
; size 1 = third of screen
; Alt+E: choose the window for opcacity change
!e:: ;Set window
WinGetTitle, WindowTitle, A
return
+!s:: ;Alt+Shift+S: Save all notepad instance
ClipSaved := ClipboardAll ; 把剪贴板的所有内容保存到您选择的变量中.
LastClip := ""
WinGet, id, list, *无标题 - 记事本, ,,
Loop, %id%
{
this_id := id%A_Index%
WinActivate, ahk_id %this_id%
Send ^A
Send ^C
Sleep 500
WinMinimize, ahk_id %this_id%
WinGetClass, this_class, ahk_id %this_id%
WinGetTitle, this_title, ahk_id %this_id%
LastClip = %LastClip% `r`n-------`r`n %ClipBoard%
ToolTip , Saving All Untitled Notepad Instances `n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n
}
ClipBoard := LastClip
; ToolTip , %ClipBoard%
Run notepad.exe
Sleep 1000
Send ^V
Sleep 1000
Clipboard := ClipSaved ; 恢复剪贴板为原来的内容. 注意这里使用 Clipboard (不是 ClipboardAll).
ClipSaved = ; 在原来的剪贴板含大量内容时释放内存.
#Persistent
ToolTip, Done
SetTimer, RemoveToolTip, 2500
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
return
+!d:: ;Alt+Shift+D: Close all untitled notepad instance
WinGet, id, list, *无标题 - 记事本, ,,
Loop, %id%
{
this_id := id%A_Index%
WinActivate, ahk_id %this_id%
WinGetClass, this_class, ahk_id %this_id%
WinGetTitle, this_title, ahk_id %this_id%
ToolTip , Closing All Untitled Notepad Instances `n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n
WinClose, ahk_id %this_id%
Send Right
Send Enter
Sleep 200
}
#Persistent
ToolTip, Done
SetTimer, RemoveToolTip, 5000
return
return
ResizeWin(dir = 1, size = 0)
{
WinGet activeWin, ID, A
activeMon := GetMonitorIndexFromWindow(activeWin)
SysGet, MonitorWorkArea, MonitorWorkArea, %activeMon%
w := MonitorWorkAreaRight - MonitorWorkAreaLeft
if (size == 0)
h := (MonitorWorkAreaBottom - MonitorWorkAreaTop)/2
else
h := (MonitorWorkAreaBottom - MonitorWorkAreaTop)/3
if (dir == 1)
t := MonitorWorkAreaBottom - h
else
t := MonitorWorkAreaTop
WinMove,A,,%MonitorWorkAreaLeft%,%t%,%w%,%h%
}
GetMonitorIndexFromWindow(windowHandle)
{
; Starts with 1.
monitorIndex := 1
VarSetCapacity(monitorInfo, 40)
NumPut(40, monitorInfo)
if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
&& DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
{
monitorLeft := NumGet(monitorInfo, 4, "Int")
monitorTop := NumGet(monitorInfo, 8, "Int")
monitorRight := NumGet(monitorInfo, 12, "Int")
monitorBottom := NumGet(monitorInfo, 16, "Int")
workLeft := NumGet(monitorInfo, 20, "Int")
workTop := NumGet(monitorInfo, 24, "Int")
workRight := NumGet(monitorInfo, 28, "Int")
workBottom := NumGet(monitorInfo, 32, "Int")
isPrimary := NumGet(monitorInfo, 36, "Int") & 1
SysGet, monitorCount, MonitorCount
Loop, %monitorCount%
{
SysGet, tempMon, Monitor, %A_Index%
; Compare location to determine the monitor index.
if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop)
and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom))
{
monitorIndex := A_Index
break
}
}
}
return %monitorIndex%
}
; Win+Alt+Up: Resize current active window to upper half
#!Up::ResizeWin(0)
; Win+Alt+Up: Resize current active window to lower half
#!Down::ResizeWin(1)
; Not used... 1/3 height resize
^#!Up::ResizeWin(0,1)
^#!Down::ResizeWin(1,1)
RunWaitOne(command) {
; WshShell 对象: http://msdn.microsoft.com/en-us/library/aew9yb99
shell := ComObjCreate("WScript.Shell")
; 通过 cmd.exe 执行单条命令
exec := shell.Exec(ComSpec " /C " command)
; 读取并返回命令的输出
return exec.StdOut.ReadAll()
}
#!O::
Run, Explorer.exe
Return
; #!K::
; run, %comspec% /c taskkill /f /im explorer.exe ,,hide
; Return
^+v:: ; Text?Conly paste from ClipBoard
Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard% ; Convert to text
Send ^v ; For best compatibility: SendPlay
Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
ClipBoard = %Clip0% ; Restore original ClipBoard
VarSetCapacity(Clip0, 0) ; Free memory
Return
; Fix OneNote horizontal scrolling
; source: https://www.reddit.com/r/OneNote/comments/3lybf1/horizontal_scrolling/
~LShift & WheelUp:: ; Scroll left.
ControlGetFocus, fcontrol, A
Loop 5 ; <-- Increase or decrease this value to scroll faster or slower.
SendMessage, 0x114, 0, 0, %fcontrol%, A ; 0x114 is WM_HSCROLL and the 0 after it is SB_LINERIGHT.
return
~LShift & WheelDown:: ; Scroll right.
ControlGetFocus, fcontrol, A
Loop 5 ; <-- Increase or decrease this value to scroll faster or slower.
SendMessage, 0x114, 1, 0, %fcontrol%, A ; 0x114 is WM_HSCROLL and the 1 after it is SB_LINELEFT.
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment