;010_跟随Windows7一起启动的AutoHotkey全自动化热键脚本源代码(长期实际测试完美进化版)
2021-05-04 12:27
                         标签:time   efi   系统变量   .exe   bsp   parse   wait   tab   false    ;010_跟随Windows7一起启动的AutoHotkey全自动化热键脚本源代码(长期实际测试完美进化版)   ; ============ 此AutoHotkey脚本从此行开始 ============================= ; ============ 防止重复运行此脚本 ============================= ; ============ 设置变量 ============================= ; 设置此脚本的当前工作目录 ; 是否需要锁定电脑 ; ============ 设置无窗口快捷键  ============================= ; 按热键`(~),打开固体移动硬盘的文档表格专用文件夹 ; 按热键F9,加密压缩备份固态优盘中的文档表格到本地磁盘分区D盘 ; 按热键Win+n,打开或者隐藏Notepad++文本文件编辑软件窗口 ; 按热键Win+f,打开或者隐藏Everything文件搜索软件 ; 按热键Win+h,打开或者隐藏Hddb文件搜索软件 ; 按热键Win+v,打开或者隐藏FileLocatorPro文档表格正文内容搜索查找软件 ; 按热键Win+s,打开或者隐藏SogouExplorer搜狗高速浏览器,有任何疑问可以百度一下,百科一下 ; 进入休眠状态,如有关闭休眠则进入待机状态 ; 编辑此脚本 ; 打开AutoHotkey中文CHM帮助文档 ; 重新加载此脚本 ; 按热键Win+Esc黑屏锁定电脑 ; 按热键Alt+q解锁电脑 ; 按热键Win+g,打开或者隐藏MasterSeeker文件搜索软件 ; 按热键Win+e,打开或者隐藏TotalCommander 8.52a 文件管理,请使用8.52a版本,不要使用其他版本 ; ============ 设置系统变量  ============================= ; ============ 启动计时器  ============================= ; 复制此脚本到各磁盘分区,以防止丢失源代码 ; ============ 自定义快捷键功能过程函数子程序 ============================= TimerAutoBackupWPS: ; 按热键`(~),打开固体移动硬盘的文档表格专用文件夹 ; 按热键F9,测试并加密压缩备份固态优盘中的文档表格到本地磁盘分区D盘 ; 按热键Win+n,打开或者隐藏Notepad++文本文件编辑软件窗口 ; 按热键Win+f,打开或者隐藏Everything文件搜索软件 TimerEverythingControlFocus: ; 按热键Win+h,打开或者隐藏Hddb文件搜索软件 TimerHddbControlFocus: ; 按热键Win+w,打开或者隐藏FileLocatorPro文档表格正文内容搜索查找软件 ; 按热键Win+s,打开或者隐藏SogouExplorer搜狗高速浏览器,有任何疑问可以百度一下,百科一下 ; 进入休眠状态,如有关闭休眠则进入待机状态 ; 编辑此脚本 SubAutoHotkeyCHM: ; 打开AutoHotkey中文CHM帮助文档 ; 重新加载此脚本 ; ============ 此AutoHotkey脚本子程序过程函数定义部分 =================== ; 按热键Win+Esc黑屏锁定电脑 	if %isLockPC% 		; 新建并显示黑屏窗口 		; 屏蔽热键 ; 按热键Alt+q解锁电脑 	;显示任务栏 	; 关闭并销毁黑屏窗口 	;解锁热键 屏蔽热键: ; 按热键Win+g,打开或者隐藏MasterSeeker文件搜索软件 ; 选中MasterSeeker的搜索输入框,以便输入文件名搜索关键字 ; 按热键Win+e,打开或者隐藏TotalCommander 8.52a 文件管理,请使用8.52a版本,不要使用其他版本   TimerTimeIdlePhysical: TimerWatchTencentQQ: ; 函数定义部分 				else 			} 	} ; ============ 此AutoHotkey脚本从此行开始 ============================= ; 防止重复运行此脚本 ; ============ 此AutoHotkey脚本到此行结束 ============================= ;010_跟随Windows7一起启动的AutoHotkey全自动化热键脚本源代码(长期实际测试完美进化版) 标签:time   efi   系统变量   .exe   bsp   parse   wait   tab   false    原文地址:http://www.cnblogs.com/delphixx/p/7718545.html
; 此脚本文件名:  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
Hotkey,F9,BackupWPS
Hotkey,`#n,ActiveOrHideNotepad++
Hotkey,`#f,ActiveOrHideEverything
Hotkey,`#h,ActiveOrHideHddb
Hotkey,`#v,ActiveOrHideFileLocator
Hotkey,`#s,ActiveOrHide搜狗高速浏览器
Hotkey,Pause,SubPCSleep
Hotkey,`^!E,SubSciTE编辑此脚本
Hotkey,`^!H,SubAutoHotkeyCHM
Hotkey,`^!R,SubReloadMe
Hotkey,`#Esc,SubLockPC
Hotkey,`!q,SubUnLockPC
; MasterSeeker可以在完成所有缓存之前抢先显示部分搜索结果,但是需要dotNetFx20SP2的支持
Hotkey,`#g,ActiveOrHideMasterSeeker
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
	gosub,BackupWPS
return
ActiveOrHideUD:
	ud:=FuncSearchUSBDriver()
	if  (%ud%0)
		Run,%ud%:\1_uploadtobaidunetdisk\
return
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
ActiveOrHideNotepad++:
	ActiveOrHideWindow("Notepad++",true)
return
ActiveOrHideEverything:
	ActiveOrHideWindow("Everything",true)
	SetTimer,TimerEverythingControlFocus,1000
return
	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
ActiveOrHideHddb:
	ActiveOrHideWindow("Hddb",false)
	; 激活(选中)Hddb搜索输入框
	SetTimer,TimerHddbControlFocus,3
return
	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
ActiveOrHideFileLocator:
	ActiveOrHideWindow("FileLocator",true)
return
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
	Run,..\AutoHotkey\AutoHotkey_CN.chm
return
SubAutoHotkey中文CHM帮助文档:
	Run,..\AutoHotkey\AutoHotkey_CN.chm
return
SubReloadMe:
	Reload
return
SubLockPC:
	;关闭显示器:
	SendMessage, 0x112, 0xF170, 2,, Program Manager
	{
		; 隐藏任务栏
		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
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
ActiveOrHideMasterSeeker:
	ActiveOrHideWindow("MasterSeeker",false)
	SetTimer,TimerMasterSeekeRControlFocus,500
return
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
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
	;~ 闲置时间检查,时间单位是毫秒 1秒钟表示成 1000
	; 每3分钟检查一次键盘鼠标的闲置时间,最多6分钟闲置后黑屏挂机锁定电脑
	;~ MsgBox,%A_TimeIdlePhysical%
	Sleep,1000
	IfGreater,%A_TimeIdlePhysical%,180000
	{
		Sleep,1000
		if(A_TimeIdlePhysical>180000)
		{
			goto,SubLockPC
		}
	}
return
	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
				{
					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
}
; 此脚本文件名:  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
}
文章标题:;010_跟随Windows7一起启动的AutoHotkey全自动化热键脚本源代码(长期实际测试完美进化版)
文章链接:http://soscw.com/index.php/essay/82259.html