Skip to content

Instantly share code, notes, and snippets.

@Envl

Envl/AHKMain.ahk Secret

Last active May 15, 2023 06:26
Show Gist options
  • Save Envl/f25db79493b2a025d940b7f6dd7e6aba to your computer and use it in GitHub Desktop.
Save Envl/f25db79493b2a025d940b7f6dd7e6aba to your computer and use it in GitHub Desktop.
#h:: ; Win+H hotkey
; 获取当前选择的文本. 使用剪贴板代替
; "ControlGet Selected", 是因为它可以工作于更大范围的编辑器
; (即字处理软件). 保存剪贴板当前的内容
; 以便在后面恢复. 尽管这里只能处理纯文本,
; 但总比没有好:
AutoTrim on ; 保留剪贴板中任何前导和尾随空白字符.
ClipboardOld = %ClipboardAll%
Clipboard = ; 必须清空, 才能检测是否有效.
Send ^c
ClipWait 1
if ErrorLevel ; ClipWait 超时.
return
; 替换 CRLF 和/或 LF 为 `n 以便用于 "发送原始模式的" 热字串:
; 对其他任何在原始模式下可能出现问题
; 的字符进行相同的处理:
StringReplace, Hotstring, Clipboard, ``, ````, All ; 首先进行此替换以避免和后面的操作冲突.
StringReplace, Hotstring, Hotstring, `r`n, ``r, All ; 在 MS Word 等软件中中使用 `r 会比 `n 工作的更好.
StringReplace, Hotstring, Hotstring, `n, ``r, All
StringReplace, Hotstring, Hotstring, %A_Tab%, ``t, All
StringReplace, Hotstring, Hotstring, `;, ```;, All
Clipboard = %ClipboardOld% ; 恢复剪贴板之前的内容.
; 这里会移动 InputBox 的光标到更人性化的位置:
SetTimer, MoveCaret, 10
; 显示 InputBox, 提供默认的热字串:
InputBox, Hotstring, New Hotstring, Type your abreviation at the indicated insertion point. You can also edit the replacement text if you wish.`n`nExample entry: :R:btw`::by the way,,,,,,,, :*:`::%Hotstring%
if ErrorLevel ; 用户选择了取消.
return
IfInString, Hotstring, :*`:::
{
MsgBox You didn't provide an abbreviation. The hotstring has not been added.
return
}
; 否则添加热字串并重新加载脚本:
FileAppend, `n%Hotstring%, D:\SourceCode\AutoHotKey\addHotString.ahk ; 在开始处放置 `n 以防文件末尾没有空行.
Reload
Sleep 200 ; 如果加载成功, reload 会在 Sleep 期间关闭当前实例, 所以永远不会执行到下面的语句.
MsgBox, 4,, The hotstring just added appears to be improperly formatted. Would you like to open the script for editing? Note that the bad hotstring is at the bottom of the script.
IfMsgBox, Yes, Edit
return
MoveCaret:
IfWinNotActive, New Hotstring
return
; 否则移动 InputBox 中的光标到用户输入缩写的位置.
Send {Home}{Right 3}
SetTimer, MoveCaret, Off
return
:*:;;af::
SendRaw, ()=>{}
Send, {Left}{Left}{Left}{Left}{Left}
Return
:*:;;ll::
SendRaw, //// ////////////
Send, {home}{Right}{Right}{Right}{Right}{Right}
Return
:*:;;mm::
SendRaw, //////// ////////
Send, {left}{left}{left}{left}{left}{left}{left}{left}{left}
Return
:*:;;rr::
SendRaw, //////////// ////
Send, {left}{left}{left}{left}{left}
Return
; today string
:*:;;tm::
FormatTime, today
Send,%today%
Return
:*:;;ipd::ipdw_project2018
:*:;;js::
send,\``\``\``js{enter}\``\``\``{left}{left}{left}{left}{left}{left}
Return
:*:;;cn::
SendRaw, className=''
send,{left}
Return
:*:;;pc::
SendRaw, {`` ${props.className?props.className:''}``}
Return
;下面都是脚本addHotString自动添加的 HotString
:*:;;lorem::Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tincidunt diam felis, sed tempor est pellentesque vel. Mauris tempus convallis.
:*:;;pcn::${{}props.className ? props.className : ''`{}}
:*:;;cln::${{}props.className ? props.className : ''`{}}
;管理员权限运行本脚本
Loop, %0% ; For each parameter:
{
param := %A_Index% ; Fetch the contents of the variable whose name is contained in A_Index.
params .= A_Space . param
}
ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
if not A_IsAdmin
{
If A_IsCompiled
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1)
Else
DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1)
ExitApp
}
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
#SingleInstance force
#MaxHotkeysPerInterval 1000
SetCapsLockState, AlwaysOff
Process, Priority,, High ;高优先级
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
;键盘映射
#include KeyMap.ahk
;番茄钟脚本 ;;pomo
;; #include Pomo.ahk
;添加热词脚本 win + h
#include addHotString.ahk
;移动窗口脚本 alt + 空格
#include altMove.ahk
;设置退出脚本的时候调用的函数
OnExit("CleanUpFunc")
;退出脚本时自动调用的函数
CleanUpFunc(exitReason,exitCode)
{
ToolTip, %exitReason%---%exitCode%
;注销 OnWin 的消息监听
Sleep, 1000
}
;重启脚本快捷键;
^End::
Send, ^s
ToolTip, Reloading Script
Reload ;重启脚本快捷键
return
;锁定电脑
:*:;;lock::
key:= "magic"
i:=1
BlockInput MouseMove
MouseMove,3, 3
; MsgBox, , Locked up, 鼠标键盘已锁定
Gui, locker:New
gui, locker:
gui, font,s15,MS sans serif
Gui, locker:Color,0x00000000
Gui, locker:Add, Text,x280 y15 cWhite , Mouse and Keyboard Locked
Gui ,locker:+AlwaysOnTop -Caption +Owner
Gui, locker:Show,W800 H60 Center
Loop
{
Input, c, L1
if(c = SubStr(key, i, 1)){
i++
}
if(i>StrLen(key)){
BlockInput, MouseMoveOff
BlockInput, Off
Gui, Hide
GuiClose:
break
}
}
Return
:*:;;tst::
CustomColor := "EEAA99" ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s32 ; Set a large font size (32-point).
Gui, Add, Text, vMyText cLime, XXXXX YYYYY ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor% 150
SetTimer, UpdateOSD, 20
Gosub, UpdateOSD ; Make the first update immediate rather than waiting for the timer.
Gui, Show, x0 y400 NoActivate ; NoActivate avoids deactivating the currently active window.
return
UpdateOSD:
MouseGetPos, MouseX, MouseY
GuiControl,, MyText, X%MouseX%, Y%MouseY%
return
Gui, Add, Tab,, FirstTab|SecondTab|ThirdTabGuiEscape:
Gui, Submit ; Save each control's contents to its associated variable.
MsgBox You entered:`n%MyCheckbox%`n%MyRadio%`n%MyEdit%
ExitApp
;打开微信, 微信没打开就打开, 打开了就调用快捷键
^+w::
Process,Exist, WeChatStore.exe
if ErrorLevel ; 非0, 说明找到了该进程 值为进程的PID
{
Send, ^!{w}
Return
}
{
Send, #{7}
Return
}
Return
;鼠标无限连击
#!c::
Loop
{
ToolTip, Clicking Mouse press <<T>> to stop
Sleep, 2
GetKeyState, state, t, P
if state=D
{
ToolTip
break
}
MouseClick
}
Return
;获取像素点颜色
#c::
MouseGetPos, mx, my
PixelGetColor, color, %mx%, %my%,RGB
color := SubStr(color, 3)
ToolTip, #%color%
Sleep, 300 ;等待c键释放
counter:=0
Loop{
Sleep, 50
counter+=50
GetKeyState, state, c, P
if state=D
{
ToolTip, Copied to Clipboard
Clipboard=%color%
break
}
; ToolTip, %counter%
if counter>2000
break
}
sleep 500
ToolTip
Return
#o:: ; Win+O 热键关闭显示器.
Sleep 1000 ; 让用户有机会释放按键 (以防释放它们时再次唤醒显示器).
; 关闭显示器:
SendMessage, 0x112, 0xF170, 2,, Program Manager ; 0x112 为 WM_SYSCOMMAND, 0xF170 为 SC_MONITORPOWER.
; 对上面命令的注释: 使用 -1 代替 2 来打开显示器.
; 使用 1 代替 2 来激活显示器的节能模式.
return
;屏幕顶部 wheel 切换虚拟桌面
WheelUp::
CoordMode, Mouse, Screen
MouseGetPos, mx, my,
if (mx<=4 || my<=10)
{
send, #^{left}
IfWinExist,sPomodoro
{
WinHide,sPomodoro
SetTimer, ReshowPomo, 1000
}
}
Else Send, {WheelUp}
Return
WheelDown::
CoordMode, Mouse, Screen
MouseGetPos,mx , my
If (mx<=4 || my<=10)
{
Send, #^{Right}
IfWinExist,sPomodoro
{
WinHide,sPomodoro
SetTimer, ReshowPomo, 1000
}
}
Else Send, {WheelDown}
Return
; reshow pomo after change 虚拟桌面
ReshowPomo:
SetTimer, ReshowPomo, Off
WinShow, sPomodoro
Return
;重启 WGestures
:*:;;wges::
{
Run, C:\Program Files (x86)\WGestures\WGestures.exe
}
; 重命名为scr后缀
:*:;;wt::
Send, {F2}{End}.scr{Enter}
Sleep, 20
Send, {Enter}
Sleep, 20
Send, {Enter}
Return
;鼠标移动一个像素
^Left::MouseMove, -1, 0, , R
^Right::MouseMove, 1, 0, , R
^Up::MouseMove, 0, -1, , R
^Down::MouseMove, 0, 1, , R
;任意位置拖动窗口
LAlt & Space::
ToolTip, 移动鼠标以改变窗口位置
;设置鼠标坐标模式为相对屏幕
CoordMode, Mouse, Screen
;获取初始鼠标位置
MouseGetPos, mX0, mY0 , hwnd
IfWinExist, ahk_id %hwnd%
{
;获取初始窗口位置
WinGetPos, wX0, wY0
;激活鼠标下窗口
WinActivate, ahk_id %hwnd%
}
Else
Return
Loop{
GetKeyState, state, LAlt, P
if state = U
{
ToolTip
break
}
GetKeyState, mState, Space, P
if mState = U
{
ToolTip
break
}
;上面只要 m 或者 RAlt 松开都会退出
;获取当前鼠标位置
MouseGetPos, mX, mY
SetWinDelay, -1
WinMove, ahk_id %hwnd%, , wX0+mX-mX0, wY0+mY-mY0
}
Return
;中文引用括号
![::send,{U+300C}
!]::send,{U+300D}
; 左右移动4个字符
$!^j::send,{left}{left}{left}{left} ; $ pre-fix to avoid self invoking
$!^l::send,{right}{right}{right}{right}
$+!^j::send,+{left}+{left}+{left}+{left}
$+!^l::send,+{right}+{right}+{right}+{right}
; 上下移动4个字符
$!^i::send,{up}{up}{up}{up} ; $ pre-fix to avoid self invoking
$!^k::send,{down}{down}{down}{down}
$+!^i::send,+{up}+{up}+{up}+{up}
$+!^k::send,+{down}+{down}+{down}+{down}
; 左右移动 10 个字符
$!^h::send,{left}{left}{left}{left}{left}{left}{left}{left}{left}{left} ; $ pre-fix to avoid self invoking
$!^;::send,{right}{right}{right}{right}{right}{right}{right}{right}{right}{right}
$+!^h::send,+{left}+{left}+{left}+{left}+{left}+{left}+{left}+{left}+{left}+{left}
$+!^;::send,+{right}+{right}+{right}+{right}+{right}+{right}+{right}+{right}+{right}+{right}
;listary
CapsLock & n::send,#{n}
;鼠标点击
!c::MouseClick
CapsLock & ,::MouseClick
CapsLock & .::MouseClick, Right
;alt + lkji 上下左右
!j::Send, {left}
!l::Send, {Right}
!i::Send, {Up}
!k::Send, {Down}
!o::Send,{End}
!u::Send,{Home}
; ;选取
!+j::Send, +{Left}
!+i::Send, +{Up}
!+k::Send, +{Down}
!+l::Send, +{Right}
!+u::Send,+{Home}
!+o::Send,+{End}
;上页翻页键映射
!h::Send {PgUp}{down}
!;::Send {PgDn}{up}
;媒体播放 上一首下一首
^!p::Send, {Media_Play_Pause}
^+Right::Send, {Media_Next}
^+left::Send, {Media_Prev}
; Volumne
!-::send,{Volume_Down}
!=::send,{Volume_Up}
; Capslock + hjkl (left, down, up, right)
Capslock & j::Send {Blind}{Left DownTemp}
Capslock & j up::Send {Blind}{Left Up}
Capslock & k::Send {Blind}{Down DownTemp}
Capslock & k up::Send {Blind}{Down Up}
Capslock & i::Send {Blind}{Up DownTemp}
Capslock & i up::Send {Blind}{Up Up}
Capslock & l::Send {Blind}{Right DownTemp}
Capslock & l up::Send {Blind}{Right Up}
; uo (home, end)
Capslock & u::Send {Blind}{Home DownTemp}
Capslock & u up::Send {Blind}{Home Up}
Capslock & o::Send {Blind}{end DownTemp}
Capslock & o up::Send {Blind}{end Up}
; h; (pgup, pgdn)
Capslock & h::Send {Blind}{pgup DownTemp}
Capslock & h up::Send, {Blind}{pgup up}
Capslock & `;::Send {Blind}{pgdn DownTemp}
Capslock & `; up::Send {Blind}{pgdn up}
; Ctrl B
CapsLock & b::send,^{b}
; 切换虚拟桌面
CapsLock & [::send,#^{left}
CapsLock & ]::send,#^{right}
; F11
CapsLock & f:: send,{f11}
CapsLock & Tab:: send,{alt DownTemp}{Tab }
; telegram
+^x::send,#6
; Capslock + num = F{num}
CapsLock & 1::send,{f1}
CapsLock & 2::send,{f2}
CapsLock & 3::send,{f3}
CapsLock & 4::send,{f4}
CapsLock & 5::send,{f5}
CapsLock & 6::send,{f6}
CapsLock & 7::send,{f7}
CapsLock & 8::send,{f8}
CapsLock & 9::send,{f9}
CapsLock & 0::send,{f10}
CapsLock & -::send,{f11}
CapsLock & +::send,{f12}
; Esc`````
CapsLock::Send {Esc Down}
CapsLock up::Send {Esc Up}
;; Capslock itself
Capslock & Space::
If GetKeyState("CapsLock", "T") = 1
SetCapsLockState, AlwaysOff
Else
SetCapsLockState, AlwaysOn
Return
;选择一行
LAlt & a::
CapsLock & a::
Send {End}
Send +{Home}
; Send +{Home}
return
; Ctrol + 1234 for vscode
#IfWinActive, ahk_exe code.exe
Capslock & s::send,^{1}
Capslock & d::send,^{2}
Capslock & w::send,^{3}
Capslock & e::send,^{4}
alt::return
Capslock & t::send,^{w}
Capslock & p::send,^{p}
; line move/copy
^!i::Send, !{Up}
^!k::Send, !{Down}
+^!i::Send, !+{Up}
+^!k::Send, !+{Down}
; console
CapsLock & c:: send,^{``}
; side bar
CapsLock & b::send,^{b}
#if
; ;;;;;; For Chrome, Chrome_edge
; #IfWinActive, ahk_exe chrome.exe
#If WinActive("ahk_exe chrome.exe") || WinActive("ahk_exe msedge.exe") || WinActive("ahk_exe ApplicationFrameHost.exe")||WinActive("ahk_exe firefox.exe")
; ctrl + w/r/t
CapsLock & w:: Send,^w
CapsLock & r:: Send,^r
CapsLock & t:: Send,^t
; switch TAB
CapsLock & j:: Send, ^+{Tab}
CapsLock & k:: Send,^{Tab}
#If
;; intellij idea
#IfWinActive, ahk_exe idea64.exe
; line move/copy
^!i::Send, ^+{Up}
^!k::Send, ^+{Down}
; alt+up down left Right
^i::Send,!{up}
^k::Send,!{down}
^j::Send,!{left}
^l::Send,!{right}
; format code
!f::SendInput,^!{l}
#if
CapsLock & p::
global showWin:=not showWin
Gosub, ToggleApp
Return
CapsLock & z::
isPomo:=not isPomo
Return
CapsLock & q::
:*:qwer::
:*:;;pom::
if not isInited{
isInited:=True
Gosub, Init
}
WinShow, sPomodoro
Gui sPomo:+LastFound
if(PomoRunning){
PomoRunning:=False
GuiControl,sPomo:,PomoStatus,(╯°Д° ) ╯ ┻━┻
GuiControl,sPomo:Move,PomoStatus,x5
WinSet, Region,0-0 w150 h40 R2-2
Goto, ClosePomo
}
PomoRunning:=True
GuiControl,sPomo:,PomoStatus,(╯°Д° ) ╯
WinSet, Region,0-0 w100 h40 R2-2
; Gui, sPomo:Show,NoActivate
WinMove, sPomodoro,,0,%yPos%
Goto, StartPomo
Return
Init:
;; Variables
showWin=true
isPomo:=True ;; Pomo or EyeCare
AppRunning:=True
PomoRunning:=False
tomatoTime:=1500 ;;25min*60s
readingTime:=1200 ;;20min*60s
eyeCareTime:=20000 ;;20s*1000ms
relaxTime:=300000 ;;5min*60s*1000ms
yPos:=A_ScreenHeight*0.85
isOnTop:=True
isHidden:=False
;; Register Windows Events
OnMessage(0x200,"WM_MOUSEMOVE")
OnMessage(0x201, "WM_LBUTTONDOWN")
OnMessage(0x202, "WM_LBUTTONUP")
OnMessage(0x204, "WM_RBUTTONDOWN")
;; Monitor tasks
SetTimer, CheckFullScrn, 3000 ; Periodically check Fullscreen application
;; GUI for eye care
Gui ,eyeCare:+LastFound +AlwaysOnTop
Gui, eyeCare:-Caption +Owner -SysMenu
gui, eyeCare:font,s16 w700 q5,Tahoma
Gui, eyeCare:Color,000000
WinSet, Transparent, 180
xx:=A_ScreenWidth/3
Gui, eyeCare: Add,Text,cWhite w%A_ScreenWidth% x%xx%, 眼睛可以休息一下
Gui,eyeCare:Show,NoActivate center, eyeRelax
WinHide,eyeRelax
;; GUI
Gui ,sPomo:+LastFound +AlwaysOnTop
Gui, sPomo:-Caption +Owner -SysMenu
gui, sPomo:font,s16 w700 q5,Tahoma
Gui, sPomo:Color,000000
Gui, sPomo:Add, Text, xp-15 yp+7 w200 cWhite vPomoStatus,(╯°Д° ) ╯
WinSet, Transparent, 210
WinSet, Region,0-0 w100 h40 R2-2
Gui, sPomo:Show,NoActivate x0 y%yPos%,sPomodoro
;; Righ Click Menu
Menu, rMenu, Add, Hide, ToggleApp
Menu, rMenu, Add ; Add a separator line.
Menu, rMenu, Add, sPomo by @GnimOay, rMenuHandler
;; Tray Menu
Menu,Tray,Add
Menu,Tray,Add,Heyyyy,ClosePomo
Return
StartPomo:
WinShow, sPomodoro
WinHide,eyeRelax
SoundPlay, start.mp3
SetTimer, StartPomo, Off
SetTimer, TickTick, 1000
timeElapsed:=0
energy:=1
min:=1
Return
TickTick:
timeElapsed+=1.0 ;; +1s
totalTime:=isPomo?tomatoTime:readingTime
timeLeft:=totalTime-timeElapsed
min:=Format("{:02i}",Floor(timeLeft/60))
sec:=Format("{:02i}",Floor(timeLeft-min*60))
; energy:=1-timeElapsed/()
if(energy<=0 or min<0){
SetTimer, TickTick, Off
SoundPlay, end.mp3
Goto, Relax
}
; display:=energy*10
display=%min%`:%sec%
GuiControl,sPomo:Text,PomoStatus,%display%
GuiControl,sPomo:Move,PomoStatus,x18
Return
Relax:
if(isPomo){
GuiControl,sPomo:,PomoStatus,(╯°Д° ) ╯
GuiControl,sPomo:Move,PomoStatus,x5
}
else{
WinHide,sPomodoro
WinShow, eyeRelax
}
tmpTime:=isPomo?relaxTime:eyeCareTime
SetTimer, StartPomo, %tmpTime%
Return
ClosePomo:
SetTimer, TickTick, Off
SetTimer, StartPomo, Off
Goto, CloseBeep
; Gui,sPomo:Destroy
Return
CloseBeep:
SoundBeep,800, 230
Return
ToggleApp:
if not showWin
WinHide,sPomodoro
Else
WinShow, sPomodoro
Return
rMenuHandler:
; Tooltip, You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return
WM_MOUSEMOVE( wparam, lparam, msg, hwnd ){
if wparam = 1 ; LButton
PostMessage, 0xA1, 2 ; WM_NCLBUTTONDOWN
}
WM_RBUTTONDOWN(){
Menu,rMenu,Show
}
CheckFullScrn:
global showWin
WinGetActiveTitle, title
if isWindowFullScreen(title){
if not isHidden{
WinHide,sPomodoro
isHidden:=True
}
}
else if isHidden and showWin{
WinShow, sPomodoro
isHidden:=False
}
Return
isWindowFullScreen( winTitle ) {
;checks if the specified window is full screen
winID := WinExist( winTitle )
If ( !winID )
Return false
WinGet style, Style, ahk_id %WinID%
WinGetPos ,,,winW,winH, %winTitle%
; 0x800000 is WS_BORDER.
; 0x20000000 is WS_MINIMIZE.
; no border and not minimized
Return ((style & 0x20800000) or winH < A_ScreenHeight or winW < A_ScreenWidth) ? false : true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment