;010_跟随Windows7一起启动的AutoHotkey全自动化热键脚本源代码(长期实际测试完美进化版)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了;010_跟随Windows7一起启动的AutoHotkey全自动化热键脚本源代码(长期实际测试完美进化版)相关的知识,希望对你有一定的参考价值。

;010_跟随Windows7一起启动的AutoHotkey全自动化热键脚本源代码(长期实际测试完美进化版)

 

; ============ 此AutoHotkey脚本从此行开始 =============================
; 此脚本文件名: d:\3_progra\ahk\hotkey\hotkey.ahk
; 此脚本作者: 徐晓亮grape
; 此脚本修改时间: 2017年10月23日 19时00分01秒
; 此脚本功能: 设置全局无窗口热键
; 最新版本网址: http://www.dwz.cn/ahkdwz
; 腾讯QQ号码: 595076941

; ============ 防止重复运行此脚本 =============================
#SingleInstance,force
loop,11
{
Sleep,11
if WinExist("http://www.dwz.cn/ahkdwz")
ExitApp
else
Gui, Show, Hide,http://www.dwz.cn/ahkdwz
}

; ============ 设置变量 =============================

; 设置此脚本的当前工作目录
SetWorkingDir,%A_ScriptDir%

; 是否需要锁定电脑
global isLockPC
isLockPC:=true

; ============ 设置无窗口快捷键 =============================

; 按热键`(~),打开固体移动硬盘的文档表格专用文件夹
Hotkey,``,ActiveOrHideUD

; 按热键F9,加密压缩备份固态优盘中的文档表格到本地磁盘分区D盘
Hotkey,F9,BackupWPS

; 按热键Win+n,打开或者隐藏Notepad++文本文件编辑软件窗口
Hotkey,`#n,ActiveOrHideNotepad++

; 按热键Win+f,打开或者隐藏Everything文件搜索软件
Hotkey,`#f,ActiveOrHideEverything

; 按热键Win+h,打开或者隐藏Hddb文件搜索软件
Hotkey,`#h,ActiveOrHideHddb

; 按热键Win+v,打开或者隐藏FileLocatorPro文档表格正文内容搜索查找软件
Hotkey,`#v,ActiveOrHideFileLocator

; 按热键Win+s,打开或者隐藏SogouExplorer搜狗高速浏览器,有任何疑问可以百度一下,百科一下
Hotkey,`#s,ActiveOrHide搜狗高速浏览器

; 进入休眠状态,如有关闭休眠则进入待机状态
Hotkey,Pause,SubPCSleep

; 编辑此脚本
Hotkey,`^!E,SubSciTE编辑此脚本

; 打开AutoHotkey中文CHM帮助文档
Hotkey,`^!H,SubAutoHotkeyCHM

; 重新加载此脚本
Hotkey,`^!R,SubReloadMe

; 按热键Win+Esc黑屏锁定电脑
Hotkey,`#Esc,SubLockPC

; 按热键Alt+q解锁电脑
Hotkey,`!q,SubUnLockPC

; 按热键Win+g,打开或者隐藏MasterSeeker文件搜索软件
; MasterSeeker可以在完成所有缓存之前抢先显示部分搜索结果,但是需要dotNetFx20SP2的支持
Hotkey,`#g,ActiveOrHideMasterSeeker

; 按热键Win+e,打开或者隐藏TotalCommander 8.52a 文件管理,请使用8.52a版本,不要使用其他版本
Hotkey,`#e,ActiveOrHideTotalCommander

; ============ 设置系统变量 =============================
#NoEnv
; #NoTrayIcon
#Persistent
#WinActivateForce
CoordMode,Mouse,Screen
CoordMode,Pixel,Screen
CoordMode,ToolTip,Screen
DetectHiddenWindows,On
ListLines,Off
SendMode,Input
SetBatchLines,-1
SetStoreCapsLockMode, On
SetTitleMatchMode,2

; ============ 启动计时器 =============================
; 每隔1小时定时自动备份一次文档表格图片,1000毫秒/秒*60秒/分钟*60分钟/小时*0.5=1800000毫秒
SetTimer,TimerAutoBackupWPS,1800000
;~ SetTimer,TimerWatchTencentQQ,30000
SetTimer,TimerTimeIdlePhysical,180000

; 复制此脚本到各磁盘分区,以防止丢失源代码
DriveName:="cdefghijklmnopqrstuvwxyz"
loop,Parse,DriveName
{
FileCreateDir,%A_LoopField%:\3_progra\ahk\Hotkey\
FileCopy,%A_ScriptDir%\Hotkey.ahk,%A_LoopField%:\3_progra\ahk\Hotkey\Hotkey_bak.ahk,1
}
;返回,等待用户输入快捷键并等待计时器定时触发
return

; ============ 自定义快捷键功能过程函数子程序 =============================

TimerAutoBackupWPS:
gosub,BackupWPS
return

; 按热键`(~),打开固体移动硬盘的文档表格专用文件夹
ActiveOrHideUD:
ud:=FuncSearchUSBDriver()
if (%ud%<>0)
Run,%ud%:\1_uploadtobaidunetdisk\
return

; 按热键F9,测试并加密压缩备份固态优盘中的文档表格到本地磁盘分区D盘
BackupWPS:
ud:=FuncSearchUSBDriver()
if (%ud%<>0)
{
FileCreateDir,D:\BackupWPS\
Run,..\WinRAR\WinRAR.exe a -agDD -ed -ep2 -hpd41d8cd9 -or -k -m5 -r D:\BackupWPS\BackupWPS_.rar %ud%:\1_uploadtobaidunetdisk\*.txt %ud%:\1_uploadtobaidunetdisk\*.ahk %ud%:\1_uploadtobaidunetdisk\*.csv %ud%:\1_uploadtobaidunetdisk\*.docx %ud%:\1_uploadtobaidunetdisk\*.doc %ud%:\1_uploadtobaidunetdisk\*.et %ud%:\1_uploadtobaidunetdisk\*.jpg %ud%:\1_uploadtobaidunetdisk\*.pdf %ud%:\1_uploadtobaidunetdisk\*.wps %ud%:\1_uploadtobaidunetdisk\*.xls %ud%:\1_uploadtobaidunetdisk\*.xlsx
}
else
{
MsgBox, 无法备份固态优盘中的文档表格请重新插拔优盘再试
Sleep,3000
MsgBox, 无法备份固态优盘中的文档表格请重新插拔优盘再试
}
return

; 按热键Win+n,打开或者隐藏Notepad++文本文件编辑软件窗口
ActiveOrHideNotepad++:
ActiveOrHideWindow("Notepad++",true)
return

; 按热键Win+f,打开或者隐藏Everything文件搜索软件
ActiveOrHideEverything:
ActiveOrHideWindow("Everything",true)
SetTimer,TimerEverythingControlFocus,1000
return

TimerEverythingControlFocus:
loop,9
{
; 等待Everything搜索软件窗口激活,超时0.1秒
; 等待超过0.1秒后还没有激活则继续执行下一行代码
WinWaitActive, ahk_class EVERYTHING, , 0.1
IfWinActive,ahk_class EVERYTHING
{
ControlFocus,Edit1
Send,^a
}
Sleep,9
ControlGetFocus, OutputVar,ahk_class EVERYTHING
Sleep,9
if (%OutputVar%=Edit1) and (WinActive(ahk_class EVERYTHING))
{
SetTimer,TimerEverythingControlFocus,Delete
break
}
}
return

; 按热键Win+h,打开或者隐藏Hddb文件搜索软件
ActiveOrHideHddb:
ActiveOrHideWindow("Hddb",false)
; 激活(选中)Hddb搜索输入框
SetTimer,TimerHddbControlFocus,3
return

TimerHddbControlFocus:
loop,99
{
ControlClick,Button1,Hddb,数据库里没有任何信息
ControlClick,Button1,Hddb,必须重建数据库才能继续
ControlClick,Button1,Hddb,上次运行的Hddb没有正常关闭
WinClose,每日一贴,启动时显示
WinKill,每日一贴,启动时显示
Sleep,9
}
WinWaitActive,Hddb, , 0.1
ControlFocus,RICHEDIT50W1
Send,{home}{ShiftDown}{End}{ShiftUp}
;~ ControlGetFocus, OutputVar2,ahk_class Hddb_Main_Window
;~ MsgBox, Control with focus = %OutputVar2%
;~ if(%OutputVar2%=)
;~ break
SetTimer,TimerHddbControlFocus,Delete
return

; 按热键Win+w,打开或者隐藏FileLocatorPro文档表格正文内容搜索查找软件
ActiveOrHideFileLocator:
ActiveOrHideWindow("FileLocator",true)
return

; 按热键Win+s,打开或者隐藏SogouExplorer搜狗高速浏览器,有任何疑问可以百度一下,百科一下
ActiveOrHide搜狗高速浏览器:
ActiveOrHideWindow("搜狗高速浏览器",true)
return

; 进入休眠状态,如有关闭休眠则进入待机状态
SubPCSleep:
DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
return

; 编辑此脚本
SubSciTE编辑此脚本:
Run,..\AutoHotkey\SciTE\SciTE.exe %A_ScriptDir%\Hotkey.ahk
return

SubAutoHotkeyCHM:
Run,..\AutoHotkey\AutoHotkey_CN.chm
return

; 打开AutoHotkey中文CHM帮助文档
SubAutoHotkey中文CHM帮助文档:
Run,..\AutoHotkey\AutoHotkey_CN.chm
return

; 重新加载此脚本
SubReloadMe:
Reload
return

; ============ 此AutoHotkey脚本子程序过程函数定义部分 ===================

; 按热键Win+Esc黑屏锁定电脑
SubLockPC:
;关闭显示器:
SendMessage, 0x112, 0xF170, 2,, Program Manager

if %isLockPC%
{
; 隐藏任务栏
hw_tray := DllCall( "FindWindowEx", "uint",0, "uint",0, "str","Shell_TrayWnd", "uint",0 )
WinHide, ahk_id %hw_tray%
WinHide AutoHotkeyclass ShellTrayWnd

; 新建并显示黑屏窗口
Gui, LockGui:New
Gui, LockGui:Color,0x00000000
Gui, LockGui:-Resize -Caption
Gui, LockGui:Show,Maximize CEnter

; 屏蔽热键
Hotkey,#d,屏蔽热键,On
Hotkey,!tab,屏蔽热键,On
Hotkey,^esc,屏蔽热键,On
Hotkey,LWin,屏蔽热键,On
Hotkey,RWin,屏蔽热键,On
MouseMove,3000,3000
}
return

; 按热键Alt+q解锁电脑
SubUnLockPC:

;显示任务栏
hw_tray := DllCall( "FindWindowEx", "uint",0, "uint",0, "str","Shell_TrayWnd", "uint",0 )
WinShow, ahk_id %hw_tray%
WinShow AutoHotkeyclass ShellTrayWnd

; 关闭并销毁黑屏窗口
Gui, LockGui:Cancel
Gui, LockGui:Destroy

;解锁热键
Hotkey,#d,屏蔽热键,Off
Hotkey,!tab,屏蔽热键,Off
Hotkey,^esc,屏蔽热键,Off
Hotkey,LWin,屏蔽热键,Off
Hotkey,RWin,屏蔽热键,Off
MouseMove,AScreenWidth/2,AScreenHeight/2
;// BlockInput,MouseMoveOff
;// DllCall("ClipCursor", UInt, &UUUUU)
Reload
Sleep,1000
Reload
return

屏蔽热键:
return

; 按热键Win+g,打开或者隐藏MasterSeeker文件搜索软件
ActiveOrHideMasterSeeker:
ActiveOrHideWindow("MasterSeeker",false)
SetTimer,TimerMasterSeekeRControlFocus,500
return

; 选中MasterSeeker的搜索输入框,以便输入文件名搜索关键字
TimerMasterSeekerControlFocus:
loop,9
{
WinWaitActive,ahk_class WindowsForms10.Window.8.app.0.218f99c, , 0.1
IfWinActive,ahk_class WindowsForms10.Window.8.app.0.218f99c
{
ControlFocus,Filename
Send,^a
}
Sleep,10
ControlGetFocus, OutputVar1,"ahk_class WindowsForms10.Window.8.app.0.218f99c"
Sleep,10
if (%OutputVar1%=Edit1) and (WinActive("ahk_class WindowsForms10.Window.8.app.0.218f99c"))
{
SetTimer,TimerMasterSeekeRControlFocus,Delete
;~ MsgBox,%A_Index%
break
}
}
return

; 按热键Win+e,打开或者隐藏TotalCommander 8.52a 文件管理,请使用8.52a版本,不要使用其他版本
ActiveOrHideTotalCommander:
WinGetActiveTitle, MyWinActiveTitle
IfInString,MyWinActiveTitle,8.52a
{
loop,9
{
WinMinimize,8.52a
WinHide,8.52a
WinGet,WinStyle ,Style,8.52a
; 如果成功隐藏窗口则退出loop循环
if (not(WinStyle&0x10000000))
break
if A_Index > 3
{
MsgBox, 无法隐藏窗口
goto,EndofTC ; 终止循环
}
}
}
else
{
IfWinNotExist,8.52a
{
loop,9
{
Process,Exist,Totalcmd.exe
if (%ErrorLevel%=0)
Run,..\..\Totalcmd.exe,..\..\
WinWait,8.52a,,9
IfWinExist,8.52a
break
if A_Index > 3
{
MsgBox, 无法运行程序%VarExePath%%VarExeFile%
goto,EndofTC ; 终止循环
}
}
}
loop,9
{
WinShow,8.52a
WinActivate,8.52a
WinGet, winid, ID,8.52a
DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)
WinGetActiveTitle, MyWinActiveTitle
IfInString,MyWinActiveTitle,8.52a
break
if A_Index > 3
{
MsgBox, 无法激活窗口
goto,EndofTC ; 终止循环
}
}
}
EndofTC:
return

 

TimerTimeIdlePhysical:
;~ 闲置时间检查,时间单位是毫秒 1秒钟表示成 1000
; 每3分钟检查一次键盘鼠标的闲置时间,最多6分钟闲置后黑屏挂机锁定电脑
;~ MsgBox,%A_TimeIdlePhysical%
Sleep,1000
IfGreater,%A_TimeIdlePhysical%,180000
{
Sleep,1000
if(A_TimeIdlePhysical>180000)
{
goto,SubLockPC
}
}
return

TimerWatchTencentQQ:
Process,Exist,qq.exe
if (%ErrorLevel%=0)
IfExist,C:\Program Files\Tencent\QQ\Bin\QQ.exe
Run,"C:\Program Files\Tencent\QQ\Bin\QQ.exe"
else
{
MsgBox,找不到文件 C:\Program Files\Tencent\QQ\Bin\QQ.exe
SetTimer,TimerWatchTencentQQ,Delete
}
return

; 函数定义部分
; 激活或者隐藏窗口函数(窗口标题的部分字符,是否最大化窗口)
ActiveOrHideWindow(VarWinTitle:="记事本",VarisWinMax:=true)
{
WinGetActiveTitle, MyWinActiveTitle
IfInString,MyWinActiveTitle,%VarWinTitle%
{
loop,9
{
WinMinimize,%VarWinTitle%
WinHide,%VarWinTitle%
WinGet,WinStyle ,Style,%VarWinTitle%
;Common styles WS_VISIBLE 0x10000000 Creates a window that is initially visible.
; 如果成功隐藏窗口则退出loop循环
if (not(WinStyle&0x10000000))
break
if A_Index > 3
{
MsgBox, 无法隐藏窗口
goto,EndofFuncAOH ; 终止循环
}
}
}
else
{
loop,9
{
; 保存程序的文件夹名,exe可执行文件名改成与程序窗口标题相同,标题太长时截短
Process,Exist,%VarWinTitle%.exe
if (%ErrorLevel%=0)
{
IfExist,..\%VarWinTitle%\%VarWinTitle%.exe
Run,..\%VarWinTitle%\%VarWinTitle%.exe

else
{
MsgBox,没有找到 %A_WorkingDir%\..\%VarWinTitle%\%VarWinTitle%.exe
return
}

}
WinWait,%VarWinTitle%,,9
IfWinExist,%VarWinTitle%
break
if A_Index > 3
{
MsgBox, 无法运行程序 %VarWinTitle%
goto,EndofFuncAOH ; 终止循环
}
}
loop,33
{
WinShow,%VarWinTitle%
WinActivate,%VarWinTitle%
WinGet, winid, ID,%VarWinTitle%
DllCall("SwitchToThisWindow", "UInt", winid, "UInt", 1)
WinGetActiveTitle, MyWinActiveTitle
Sleep,3
IfInString,MyWinActiveTitle,%VarWinTitle%
break
if A_Index > 22
{
MsgBox, 无法激活窗口
goto,EndofFuncAOH ; 终止循环
}
}
}
EndofFuncAOH:
return
}


; 搜索卷标是pssd的固态移动硬盘
FuncSearchUSBDriver()
{
isFindud:=false
DriveGet,DriveList,List
loop,Parse,DriveList
{
DriveGet,DriveLabel,Label,%A_LoopField%:
IfInString,DriveLabel,pssd
{
return,%A_LoopField%
isFindud:=true
}
}
if (not %isFindud%)
{
MsgBox,"没有找到卷标是pssd的固态移动硬盘"
return,0

}
}

; ============ 此AutoHotkey脚本从此行开始 =============================
; 此脚本文件名: d:\3_progra\ahk\hotkey\ahk.ahk
; 此脚本作者: 徐晓亮grape
; 此脚本修改时间: 2017年10月23日 19时00分01秒
; 此脚本功能: ; 在Win7启动时自动运行 Hotkey.exe
; 最新版本网址: http://www.dwz.cn/ahkdwz
; 腾讯QQ号码: 595076941

; 防止重复运行此脚本
#SingleInstance,force
loop,11
{
Sleep,11
if WinExist("http://dwz.cn/ahkdwz")
ExitApp
else
Gui, Show, Hide,http://dwz.cn/ahkdwz
}
IfExist,D:\3_progra\ahk\Hotkey\Hotkey.exe
Run,D:\3_progra\ahk\Hotkey\Hotkey.exe
else
{
USBDriver:=SearchUSBDriver()
if (%USBDriver%<>0)
{
IfExist,%USBDriver%:\3_progra\ahk\Hotkey\Hotkey.exe
Run,%USBDriver%:\3_progra\ahk\Hotkey\Hotkey.exe
else
{
; 搜索 Hotkey.exe 文件
DriveName:="cdefghijklmnopqrstuvwxyz"
loop,Parse,DriveName
{
IfExist,%A_LoopField%:\3_progra\ahk\Hotkey\Hotkey.exe
{
Run,%A_LoopField%:\3_progra\ahk\Hotkey\Hotkey.exe
ExitApp
}
}
MsgBox,没有找到 Hotkey.exe
ExitApp
}
}
}
ExitApp
; 搜索卷标是pssd的固态移动硬盘
SearchUSBDriver()
{
isFound:=false
DriveGet,DriveList,List
loop,Parse,DriveList
{
DriveGet,DriveLabel,Label,%A_LoopField%:
IfInString,DriveLabel,pssd
{
return,%A_LoopField%
isFound:=true
}
}
if (not %isFindud%)
return,0
}

; ============ 此AutoHotkey脚本到此行结束 =============================

以上是关于;010_跟随Windows7一起启动的AutoHotkey全自动化热键脚本源代码(长期实际测试完美进化版)的主要内容,如果未能解决你的问题,请参考以下文章

ms17_010(永恒之蓝)漏洞复现详细教程

linux基础—课堂随笔010_系统启动和内核管理

010_React-组件的生命周期详解

20154314 王儒君 Exp5 MSF基础应用

Java千百问_08JDK详解(010)_javajavawjavaws有什么区别

Java之品优购部署_day01