Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Utils.ahk
#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.
#N::
Run, Notepad.exe
Return
#C::
Run, cmd.exe
Return
#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:: ;Transparency down
if Transparency > 30
{
Transparency := Transparency - 50
} else {
Transparency := 30
}
refresh()
return
!q:: ;Turn transparency up
if Transparency < 255
{
Transparency := Transparency + 50
} else {
Transparency := 255
}
refresh()
return
!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
!e:: ;Set window
WinGetTitle, WindowTitle, A
return
+!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:: ;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%
}
#!Up::ResizeWin(0)
#!Down::ResizeWin(1)
^#!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–only 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.