如何舒服的运行AutoHotkey脚本

如何舒服的运行AutoHotkey脚本

 

第1步 运行BAT批处理脚本

第2步 检测是否需要安装AutoHotkey脚本运行环境,并根据检测结果安装或不安装AutoHotkey

第3步 连接群晖NAS的WebDAV Server文件服务。

“C:Program FilesOpenBoxLabRaiDriveRaiDrive.exe”

“C:Program Files (x86)WinSCPWinSCP.com”

第4步 复制群晖NAS存储服务器上复制最新版本的AutoHotkey脚本文件到本地磁盘的指定文件夹。

“C:Program Files (x86)WinSCPWinSCP.com”

“C:WindowsSystem32Robocopy.exe”

“C:UsersAdministratorFastCopyFastCopy.exe”

第5步 运行从群晖NAS复制到本地的AutoHotkey脚本文件

“Start /Min D:greenAHKManagerAutoRun.ahk”

“Start /Min D:greenAHKManagerAHKManager.ahk”

“Start /Min D:greenAHKManagerTest.ahk”

“Start /Min D:greenAHKManagerTemp.ahk”

rem 静默复制并安装green文件夹到D盘根目录

//////////////////////////////////////////////////////////////////////
rem 1、复制文件
md D:green
%~dp0greenRobocopyrobocopy.exe %~dp0green D:green *.* /E /R:1 /V /W:1 /X /ZB

//////////////////////////////////////////////////////////////////////
rem 2、安装AutoHotkey自动化热键脚本语言编程环境
D:
cd greenAutoHotkey
rem 由于AutoHotkey的安装包会记住上次安装的位置,
rem 为了软件安装位置固定到 D:greenAutoHotkey 文件夹所以此处必需指定安装目标文件夹
D:greenAutoHotkeyAutoHotkey_1.1.33.05_setup.exe  /S /D=D:greenAutoHotkey

rem 设置ahk文件类型关联到AutoHotkeyU32.exe
rem 添加ahk文件类型鼠标右键菜单
rem 运行、编辑、编译脚本的关联,感谢作者写出这么好的脚本
D:greenAutoHotkeyautohotkeyu32.exe D:greenAutoHotkeyMenuSetup.ahk
rem ping -n 5 127.0.0.1>nul
rem D:greenAutoHotkeyautohotkeyu32.exe D:greenAutoHotkeyMenuSetup.ahk

//////////////////////////////////////////////////////////////////////
rem 3、静默安装AHKManager的自动启动快捷方式到shell:startup文件夹
copy /y %~dp0AHKManagerAHKManager.lnk "C:ProgramDataMicrosoftWindowsStart MenuProgramsStartup"
rem start shell:startup
rem D:
rem cd greenAHKManager
pushd D:greenAHKManager
start D:greenAHKManagerAHKManager.exe

//////////////////////////////////////////////////////////////////////
rem 4、去除文件和文件夹的只读属性,以便保存TC工具栏和设置
ATTRIB -R -A -S -H -I D:green*.* /S /D

//////////////////////////////////////////////////////////////////////
rem 5、运行RunZ
start D:greenRunZRunZ.exe

//////////////////////////////////////////////////////////////////////
rem 6、静默安装FastCopy到D盘green文件夹
if "%PROCESSOR_ARCHITECTURE%"=="x86" goto x86
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto x64
exit
:x64
rem md D:greenFastCopy64
rem %~dp0FastCopy32robocopy.exe %~dp0FastCopy64 D:greenFastCopy64 *.* /E /ZB
start D:greenFastCopy64FastCopy.exe
exit

:x86
rem md D:greenFastCopy32
rem %~dp0FastCopy32robocopy.exe %~dp0FastCopy32 D:greenFastCopy32 *.* /E /ZB
start D:greenFastCopy32FastCopy.exe
exit

 

AHKManager我做了小改动

;~ AHKManager.ahk
;AHK管理器AHKManager.ahk

;~ 把下面这个函数丢到任何AHK脚本中,就可以限制单进程运行。
;-- 限制单进程运行函数
OnlyOne(flag="") {
  local
  static init:=OnlyOne(A_ScriptName)
  hash:=0
  Loop, Parse, flag
    hash:=(hash*31+Ord(A_LoopField))&0xFFFFFFFF
  MutexName:="Ahk_OnlyOne_" . hash
  While (Mutex:=DllCall("OpenMutex","uint",0x100000,"int",0,"str",MutexName))
  {
    DllCall("CloseHandle", "ptr",Mutex)
    DetectHiddenWindows, % (dhw:=A_DetectHiddenWindows) ? "On":"On"
    WinGet, list, List, <<%flag%>> ahk_class AutoHotkeyGUI
    Loop, % list
    {
      WinGet, pid, PID, % "ahk_id " . list%A_Index%
      WinClose, ahk_pid %pid% ahk_class AutoHotkey,, 3
      IfWinExist, ahk_pid %pid%,, Process, Close, %pid%
    }
    DetectHiddenWindows, %dhw%
  }
  DllCall("CreateMutex", "ptr",0, "int",0, "str",MutexName)
  IfEqual, A_LastError, 0xB7, ExitApp
  Gui, __OnlyOne__: Show, Hide, <<%flag%>>
}

;~ 把上面这个函数丢到任何AHK脚本中,就可以限制单进程运行。
;~ isShow:=true
;源码
;~ 将exe文件发送到 自启动目录

; 作者:sunwind
; 日期:2013年1月29日,周二,下午3时58分
 
;描述:candy 插件 “将exe文件发送到 自启动目录”
;帮⑥① 2013-01-29 11:30:03 解决 :“经常有人喊我帮他某个软件设置成开机启动”
;配置位置:exe.ini 或者exe文件类型下
;配置项:SendTo自启动		=run|Extension发送到自启动目录.ahk  "{file:pathfull}" "{file:namenoext}"
;~ path_exe=%1%
;;   path_exe=D:toolsListary4Listary.exe
;;   SplitPath,path_exe,fileName
;;   ;~ alias=%2%
;;   RegRead, folder_startup, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders, Startup
;;   FileCreateShortcut, %path_exe%, %folder_startup%%fileName%.lnk
;;   IfExist,%folder_startup%%alias%.lnk
;;   	TrayTip,,已经成功设置%alias%自启动!,10
;;   Sleep,3000

;~ 按 {Ctrl} + {Alt} + {F12} 立即无条件终止所有脚本
Hotkey,^!F12,ExitThisApp
ExitThisApp()
{
	gosub,ExitSubNow
	ExitApp
}
;by Sixtyone At 2016.4.10
;更新说明
/*
2016.4.24:
1.运行#脚本后,gui自动隐藏;
2.启动脚本目录后,gui自动隐藏。
2016.4.17:
1. 增加过滤中使用%A_ScriptDir%变量。
2016.4.14:
1.修复2016.4.13版本中的1个bug;
2.添加文件(夹)过滤功能:添加到过滤中的文件(夹),将不会被读取到AHK管理器中;
3.修复之前版本某些脚本不能关闭问题;
4.修复脚本不能正确读取ini配置问题。
2016.4.13:
1.更新添加“Scripts文件夹内的第一层子文件夹脚本”,但所有脚本不能同名。
2016.4.11:
1.脚本库中启动条目后,焦点自带设置为上一条,正在运行库同;
2.更新脚本库双击运行脚本,正在运行库双击关闭脚本;
3.脚本库增加右键菜单:"编辑","运行"--正在运行库增加右键菜单:"编辑","重载","关闭"。
*/
#SingleInstance Force
#NoEnv
;#Warn
SetWorkingDir %A_ScriptDir%
Process, Priority,, High
DetectHiddenWindows,On
Menu, Tray, NoStandard                  ;删除自带托盘菜单
Menu, tray, add, 管理,ShowGui  ;  显示Gui
Menu, tray, add  ; 创建分隔线.
Menu, tray, add ,过滤,Menu_Tray_过滤        ;  过滤
Menu, tray, add ,脚本目录,Menu_Tray_OpenDir          ;  脚本目录
Menu, tray, add ,重启管理器,Menu_Tray_Reload          ; 重启
Menu, tray, Add
Menu, tray, Add,帮助,Help ;Help
Menu, tray, Add,关于,About ;关于
Menu, tray, Add
Menu, tray, Add, 退出, ExitSub                  ; 创建    退出
Menu, Tray, Default, 管理  ;;默认  菜单:配置
Menu, Tray, Icon, Shell32.dll, 258
;IntelligentScript:
Gui,Destroy
Gui Add, ListView, x8 y30 w200 h400 AltSubmit vScriptLibrary g运行 , 脚本名称
Gui Add, Text, x10 y3 w120 h23 +0x200, 脚本库
Gui Add, ListView, x233 y30 w200 h400 AltSubmit vScriptRun g运行2, 脚本名称
Gui Add, Text, x234 y3 w120 h23 +0x200, 已运行脚本
Gui Add, Button, x440 y30 w60 h42 gtsk_open, 启动脚本
Gui Add, Button, x440 y100 w60 h42 gtsk_restart, 重载脚本
Gui Add, Button, x440 y170 w60 h42 gtsk_close, 关闭脚本
Gui Add, Button, x440 y240 w60 h42 gMenu_Tray_OpenDir, 脚本目录
Gui Add, Button, x440 y310 w60 h42 gMenu_Tray_Reload, 重启管理器
Gui Add, Button, x440 y380 w60 h42 gExitSub, 退出
;Gui Show,, AHK管理器
Gui Default
Gui,ListView,ScriptLibrary
scriptCount = 0
IniRead,Golv,过滤.ini,过滤
OpenList := Array()
UnOpenList := Array()
FileCreateDir,%A_ScriptDir%scripts
loop, %A_ScriptDir%scripts*.ahk,,1
{
	_Golv=0
	loop,Parse,Golv,`n,`r                  ;增加过滤判断
	{
		StringReplace,_GolvPath,A_LoopField,`%A_ScriptDir`%,%A_ScriptDir%
		IfInString,A_LoopFileLongPath ,%_GolvPath%
		{
			_Golv=1
			break
		}
	}
	if  _Golv=1
		continue
	if !(A_LoopFileLongPath~="i).+?\scripts\[^\]*\?[^\]+.ahk")                          ;增加一层子文件读取
		continue
	StringReplace, MenuName, A_LoopFileName, .ahk
	scriptCount += 1
	%MenuName%_Path :=A_LoopFileLongPath
	%MenuName%_Dir :=A_LoopFileDir
	scriptsName%scriptCount% := A_LoopFileName
	;scriptsOpened%scriptCount% = 0
	UnOpenList.Insert(MenuName)
}
InsertionSort(UnOpenList)
for Index, MenuName in UnOpenList
{
	LV_Add("",MenuName)
}
LV_ModifyCol()
gosub tsk_openAll
;Gui,Show
return
运行:
if A_GuiEvent = DoubleClick
{
	goto,tsk_open
}
return
运行2:
	if A_GuiEvent = DoubleClick
		goto,tsk_close
return
GuiContextMenu:  ; 运行此标签来响应右键点击或按下 Appskey.
	if A_GuiControl = ScriptLibrary  ; 这个检查是可选的. 让它只为 ListView 中的点击显示菜单.
	{
		Gui,Default
		Gui,ListView,ScriptLibrary
		RowNumber = 0
		loop,%scriptCount%
		{
			RowNumber := LV_GetNext(RowNumber)
			if not RowNumber
				return
			break
		}
		Menu,PopC,Add,编辑,P_edit
		Menu,PopC,Add,运行,tsk_open
		Menu,PopC,Show
		return
	}
	if  A_GuiControl = ScriptRun
	{
		Gui,Default
		Gui,ListView,ScriptRun
		RowNumber = 0
		loop,%scriptCount%
		{
			RowNumber := LV_GetNext(RowNumber)
			if not RowNumber
				return
			break
		}
		Menu,PopC2,Add,编辑,P_edit
		Menu,PopC2,Add,重载,tsk_restart
		Menu,PopC2,Add,关闭,tsk_close
		Menu,PopC2,Show
		return
	}
return
P_edit:
	LV_GetText(thisScript, RowNumber)
	P_editpath :=%thisScript%_path
	Run, D:greenAutoHotkeySciTESciTE.exe  "%P_editpath%"
return
tsk_open:
	Gui,Default
	Gui,ListView,ScriptLibrary
	RowNumber = 0
	loop,%scriptCount%
	{
		RowNumber := LV_GetNext(RowNumber)
		if not RowNumber
			return
		LV_GetText(thisScript, RowNumber)
		Run,% %thisScript%_Path,% %thisScript%_Dir,,%thisScript%
		IfInString, thisScript, #
		{
			Gui, Hide
			return
		}
		;scriptsOpened%A_Index% := 1
		break
	}
	Gui,ListView,ScriptRun
	LV_Add("",ThisScript)
	LV_ModifyCol()
	Gui,ListView,ScriptLibrary
	loop, %scriptCount%
	{
		LV_GetText(outputname,A_Index,1)
		if (outputname=ThisScript)
		{
			LV_Delete(A_Index)
			if A_Index<>1
			{
				LV_Modify(A_Index-1, "Select")
			}
			else
			{
				LV_Modify(1, "Select")
			}
			break
		}
	}
	LV_ModifyCol()
return
tsk_close:
	Gui,Default
	Gui,ListView,ScriptRun
	RowNumber = 0
	loop,%scriptCount%
	{
		RowNumber := LV_GetNext(RowNumber)
		if not RowNumber
			return
		LV_GetText(thisScript, RowNumber)
		ID:=%thisScript%
		WinClose, ahk_pid %ID%
		IfWinExist,ahk_pid %ID%
			Process,Close,%ID%
		;scriptsOpened%A_Index% := 0
		break
	}
	Gui,ListView,ScriptLibrary
	LV_Add("",ThisScript)
	LV_ModifyCol()
	Gui,ListView,ScriptRun
	loop, %scriptCount%
	{
		LV_GetText(outputname,A_Index,1)
		if (outputname=thisScript)
		{
			LV_Delete(A_Index)
			if A_Index<>1
			{
				LV_Modify(A_Index-1, "Select")
			}
			else
			{
				LV_Modify(1, "Select")
			}
			break
		}
	}
	LV_ModifyCol()
return
tsk_restart:
	Gui,Default
	Gui,ListView,ScriptRun
	RowNumber = 0
	loop,%scriptCount%
	{
		RowNumber := LV_GetNext(RowNumber)
		if not RowNumber
			return
		LV_GetText(thisScript, RowNumber)
		ID:=%thisScript%
		WinClose, ahk_pid %ID%
		IfWinExist,ahk_pid %ID%
			Process,Close,%ID%
		Run,% %thisScript%_Path,% %thisScript%_Dir,,%thisScript%
		break
	}
return
tsk_openAll:
	loop, %scriptCount%
	{
		thisScript := scriptsName%A_Index%
		StringReplace, thisScript, thisScript, .ahk
		;if scriptsOpened%A_Index% = 0
		;{
		IfInString, thisScript, _          ;IfInString,%thisScript%_Path,%A_ScriptDir%Scripts_    不自动启动_文件夹内的脚本
		{
			continue
		}
		IfInString, thisScript, #
		{
			continue
		}
		Run, % %thisScript%_Path,% %thisScript%_Dir,,%thisScript%
		;scriptsOpened%A_Index% = 1
		Gui,Default
		Gui,ListView,ScriptRun
		LV_Add("",thisScript)
		LV_ModifyCol()
		Gui,ListView,ScriptLibrary
		loop, %scriptCount%
		{
			LV_GetText(outputname,A_Index,1)
			if (outputname=thisScript)
			{
				LV_Delete(A_Index)
				break
			}
		}
		LV_ModifyCol()
		;}
	}
	;Gui,Show
return
Menu_Tray_过滤:
	Run, Notepad.exe  过滤.ini
return
Menu_Tray_OpenDir:
	FileCreateDir,%A_ScriptDir%scripts
	Run, %A_ScriptDir%scripts
	Gui,Hide
return
Menu_Tray_Reload:
	Gui,Hide
	Gui,Default
	Gui,ListView,ScriptRun
	loop % LV_GetCount()
	{
		LV_GetText(thisScript, A_Index)
		ID:=%thisScript%
		WinClose, ahk_pid %ID%
		IfWinExist,ahk_pid %ID%
			Process,Close,%ID%
	}
	Reload
return
GuiEscape:
GuiClose:
	Gui, Hide
return
ExitSub:
	MsgBox,260,是否退出?,退出脚本,将退出所有经过AHK管理器启动的脚本,你是否确认退出?
	IfMsgBox No
		return
ExitSubNow:
	Gui,Hide
	Gui,Default
	Gui,ListView,ScriptRun
	loop % LV_GetCount()
	{
		LV_GetText(thisScript, A_Index)
		ID:=%thisScript%
		WinClose, ahk_pid %ID%
		IfWinExist,ahk_pid %ID%
			Process,Close,%ID%
	}
	Gui,Destroy
	ExitApp
return
InsertionSort(ByRef array)
{
	target := Array()
	count := 0
	for Index, Files in array
	{
		files%Index% := Files
		count += 1
	}
	j := 2
	while (j <= count)
	{
		key := files%j%
		i := j-1
		while (i >= 0 && key < files%i%)
		{
			k := i+1
			files%k% := files%i%
			i -= 1
		}
		k := i+1
		files%k% := key
		j += 1
	}
	loop, %count%
	{
		target.Insert(files%A_Index%)
	}
	array := target
}
About:
	MsgBox,AHK管理器`n版本号:2016.4.24`nCopyRight?2016 Sixtyone.  All Rights Reserved.`n`n关于作者:`n`tName:Sixtyone`n`tQQ:576642385
return
Help:
	MsgBox,将AHK脚本放在脚本目录下进行管理:`n1.以_开头的脚本不会自动加载`n2.以#开头的脚本为临时脚本即运行完就退出`n3.脚本名字不能有空格及除_、#以为的符号`n4.脚本不能为快捷方式
return
!`::
	;~ isShow:=!isShow
	;~ if(isShow)
	;~ {
ShowGui:
	Gui,Show,,AHK管理器
	;~ }
	;~ else
	;~ Gui,Hide
return
;~ 作者:sixtyone
;~ 链接:https://www.jianshu.com/p/d88f47fa431d
;~ 來源:简书
;~ 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

;批量删除空白行的正则表达式  ^[st]*n

 

RunZ也做了小改动,优化一下

#NoEnv
#SingleInstance, Force
#NoTrayIcon

FileEncoding, utf-8
SendMode Input
SetWorkingDir %A_ScriptDir%

; 自动生成的待搜索文件列表
global g_SearchFileList := A_ScriptDir . "ConfSearchFileList.txt"
; 用户配置的待搜索文件列表
global g_UserFileList := A_ScriptDir . "ConfUserFileList.txt"
; 配置文件
global g_ConfFile := A_ScriptDir . "ConfRunZ.ini"
; 自动写入的配置文件
global g_AutoConfFile := A_ScriptDir . "ConfRunZ.auto.ini"

if !FileExist(g_ConfFile)
{
    FileCopy, %g_ConfFile%.help.txt, %g_ConfFile%
}

if (FileExist(g_AutoConfFile ".EasyIni.bak"))
{
    MsgBox, % "发现上次写入配置的备份文件:`n"
        . g_AutoConfFile . ".EasyIni.bak"
        . "`n确定则将其恢复,否则请手动检查文件内容再继续"
    FileMove, % g_AutoConfFile ".EasyIni.bak", % g_AutoConfFile
}
else if (!FileExist(g_AutoConfFile))
{
    FileAppend, % "; 此文件由 RunZ 自动写入,如需手动修改请先关闭 RunZ !`n`n"
        . "[Auto]`n[Rank]`n[History]" , % g_AutoConfFile
}

global g_Conf := class_EasyIni(g_ConfFile)
global g_AutoConf := class_EasyIni(g_AutoConfFile)

if (g_Conf.Gui.Skin != "")
{
    global g_SkinConf := class_EasyIni(A_ScriptDir "ConfSkins" g_Conf.Gui.Skin ".ini").Gui
}
else
{
    global g_SkinConf := g_Conf.Gui
}

; 当前输入命令的参数,数组,为了方便没有添加 g_ 前缀
global Arg
; 用来调用管道的完整参数(所有列),供有必要的插件使用
global FullPipeArg
; 不能是 RunZ.ahk 的子串,否则按键绑定会有问题
global g_WindowName := "RunZ    "
; 所有命令
global g_Commands
; 当搜索无结果时使用的命令
global g_FallbackCommands
; 编辑框当前内容
global g_CurrentInput
; 当前匹配到的第一条命令
global g_CurrentCommand
; 当前匹配到的所有命令
global g_CurrentCommandList
; 每使用 tcmatch.dll 搜索多少次后重载一次,因为 tcmatch.dll 有内存泄漏
global g_ReloadTCMatchInternal := g_Conf.Config.ReloadTCMatchInternal
; 是否启用 TCMatch
global g_EnableTCMatch = TCMatchOn(g_Conf.Config.TCMatchPath)
; 列表第一列的首字母或数字
global g_FirstChar := Asc(g_SkinConf.FirstChar)
; 在列表中显示的行数
global g_DisplayRows := g_SkinConf.DisplayRows
; 命令使用了显示框
global g_UseDisplay
; 历史命令
global g_HistoryCommands
; 运行命令时临时设置,避免因为自身退出无法运行需要提权的软件
global g_DisableAutoExit
; 当前的命令在搜索结果的行数
global g_CurrentLine
; 使用备用的命令
global g_UseFallbackCommands
; 对命令结果进行实时搜索
global g_UseResultFilter
; 当参数改变后实时重新执行命令
global g_UseRealtimeExec
; 排除的命令
global g_ExcludedCommands
; 间隔运行命令的间隔时间
global g_ExecInterval
; 上次间隔运行的功能标签
global g_LastExecLabel
; 用来调用管道的参数(结果第三列)
global g_PipeArg
; 用来补全命令用的
global g_CommandFilter
; 插件列表
global g_Plugins := Object()

global g_InputArea := "Edit1"
global g_DisplayArea := "Edit3"
global g_CommandArea := "Edit4"

FileRead, currentPlugins, %A_ScriptDir%CorePlugins.ahk
needRestart := false

Loop, Files, %A_ScriptDir%Plugins*.ahk
{
    FileReadLine, firstLine, %A_LoopFileLongPath%, 1
    pluginName := StrSplit(firstLine, ":")[2]
    if (!(g_Conf.GetValue("Plugins", pluginName) == 0))
    {
        if (RegExMatch(currentPlugins, "m)" pluginName ".ahk$"))
        {
            g_Plugins.Push(pluginName)
        }
        else
        {
            FileAppend, #include *i `%A_ScriptDir`%Plugins%pluginName%.ahk`n
                , %A_ScriptDir%CorePlugins.ahk
            needRestart := true
        }
    }
}

if (needRestart)
{
    Reload
}

if (g_SkinConf.ShowTrayIcon)
{
    Menu, Tray, Icon
    Menu, Tray, NoStandard
    if (!g_Conf.Config.ExitIfInactivate)
    {
        Menu, Tray, Add, 显示 &S, ActivateRunZ
        Menu, Tray, Default, 显示 &S
        Menu, Tray, Click, 1
    }
    Menu, Tray, Add, 配置 &C, EditConfig
    Menu, Tray, Add, 帮助 &H, KeyHelp
    Menu, Tray, Add,
    Menu, Tray, Add, 重启 &R, RestartRunZ
    Menu, Tray, Add, 退出 &X, ExitRunZ
}

Menu, Tray, Icon, %A_ScriptDir%RunZ.ico

if (FileExist(g_SearchFileList))
{
    LoadFiles()
}
else
{
    GoSub, ReindexFiles
}

Gui, Color, % g_SkinConf.BackgroundColor, % g_SkinConf.EditColor

if (FileExist(A_ScriptDir "ConfSkins" g_SkinConf.BackgroundPicture))
{
    Gui, Add, Picture, x0 y0, % A_ScriptDir "ConfSkins" g_SkinConf.BackgroundPicture
}

border := 10
if (g_SkinConf.BorderSize >= 0)
{
    border := g_SkinConf.BorderSize
}
windowHeight := border * 3 + g_SkinConf.EditHeight + g_SkinConf.DisplayAreaHeight

Gui, Font, % "C" g_SkinConf.FontColor " S" g_SkinConf.FontSize, % g_SkinConf.FontName
Gui, Add, Edit, % "x" border " y" border " gProcessInputCommand -WantReturn"
        . " w" g_SkinConf.WidgetWidth " h" g_SkinConf.EditHeight,
Gui, Add, Edit, y+0 w0 h0 ReadOnly -WantReturn
Gui, Add, Button, y+0 w0 h0 Default gRunCurrentCommand
Gui, Add, Edit, % "y+" border " -VScroll ReadOnly -WantReturn"
        . " w" g_SkinConf.WidgetWidth " h" g_SkinConf.DisplayAreaHeight
        , % AlignText(SearchCommand("", true))

if (g_SkinConf.ShowCurrentCommand)
{
    Gui, Add, Edit, % "y+" border " ReadOnly"
        . " w" g_SkinConf.WidgetWidth " h" g_SkinConf.EditHeight,
    windowHeight += border + g_SkinConf.EditHeight
}

if (g_SkinConf.ShowInputBoxOnlyIfEmpty)
{
    windowHeight := border * 2 + g_SkinConf.EditHeight
    SysGet, screenHeight, 79
    windowY := "y" (screenHeight - border * 2 - g_SkinConf.EditHeight - g_SkinConf.DisplayAreaHeight) / 2
}

if (g_SkinConf.HideTitle)
{
    Gui -Caption
}

cmdlineArg = %1%
if (cmdlineArg == "--hide")
{
    hideWindow := " Hide"
}

; 晓亮修改 20210302
;~ Gui, Show, % windowY " w" border * 2 + g_SkinConf.WidgetWidth
    ;~ . " h" windowHeight hideWindow, % g_WindowName

if (g_SkinConf.RoundCorner > 0)
{
    WinSet, Region, % "0-0 w" border * 2 + g_SkinConf.WidgetWidth " h" windowHeight
        . " r" g_SkinConf.RoundCorner "-" g_SkinConf.RoundCorner, % g_WindowName
}

if (g_Conf.Config.SwitchToEngIME)
{
    SwitchToEngIME()
}

if (g_Conf.Config.WindowAlwaysOnTop)
{
    WinSet, AlwaysOnTop, On, A
}

if (g_Conf.Config.ExitIfInactivate)
{
    OnMessage(0x06, "WM_ACTIVATE")
}

OnMessage(0x0200, "WM_MOUSEMOVE")

Hotkey, IfWinActive, % g_WindowName

Hotkey, Esc, EscFunction
Hotkey, !F4, ExitRunZ

Hotkey, Tab, TabFunction
Hotkey, F1, Help
Hotkey, +F1, KeyHelp
Hotkey, F2, EditConfig
Hotkey, F3, EditAutoConfig
Hotkey, ^q, RestartRunZ
Hotkey, ^l, ClearInput
Hotkey, ^d, OpenCurrentFileDir
Hotkey, ^x, DeleteCurrentFile
Hotkey, ^s, ShowCurrentFile
Hotkey, ^r, ReindexFiles
Hotkey, ^h, DisplayHistoryCommands
Hotkey, ^n, IncreaseRank
Hotkey, ^=, IncreaseRank
Hotkey, ^p, DecreaseRank
Hotkey, ^-, DecreaseRank
Hotkey, ^f, NextPage
Hotkey, ^b, PrevPage
Hotkey, ^i, HomeKey
Hotkey, ^o, EndKey
Hotkey, ^j, NextCommand
Hotkey, ^k, PrevCommand
Hotkey, Down, NextCommand
Hotkey, Up, PrevCommand
Hotkey, ~LButton, ClickFunction
Hotkey, RButton, OpenContextMenu
Hotkey, AppsKey, OpenContextMenu
Hotkey, ^Enter, SaveResultAsArg

; 剩余按键 Ctrl + e g m t w

Loop, % g_DisplayRows
{
    key := Chr(g_FirstChar + A_Index - 1)
    ; lalt +
    Hotkey, !%key%, RunSelectedCommand
    ; tab +
    Hotkey, ~%key%, RunSelectedCommand
    ; shift +
    Hotkey, ~+%key%, GotoCommand
}

for key, label in g_Conf.Hotkey
{
    if (label != "Default")
    {
        Hotkey, %key%, %label%
    }
    else
    {
        Hotkey, %key%, Off
    }
}

Hotkey, IfWinActive

if (g_Conf.Config.EnableGlobalMenu)
{
    HotKey, #RButton, GlobalMenu
}

for key, label in g_Conf.GlobalHotkey
{
    if (label != "Default")
    {
        Hotkey, %key%, %label%
    }
    else
    {
        Hotkey, %key%, Off
    }
}

if (g_Conf.Config.SaveInputText && g_AutoConf.Auto.InputText != "")
{
    Send, % g_AutoConf.Auto.InputText
}

if (g_Conf.Config.SaveHistory)
{
    g_HistoryCommands := Object()
    LoadHistoryCommands()
}

UpdateSendTo(g_Conf.Config.CreateSendToLnk, false)
UpdateStartupLnk(g_Conf.Config.CreateStartupLnk, false)

SetTimer, WatchUserFileList, 3000
return

Default:
return

RestartRunZ:
    SaveAutoConf()
    Reload
return

Test:
    MsgBox, 测试
return

HomeKey:
    Send, {home}
return

EndKey:
    Send, {End}
return

NextPage:
    if (!g_UseDisplay)
    {
        return
    }

    ControlFocus, %g_DisplayArea%
    Send, {pgdn}
    ControlFocus, %g_InputArea%
return

PrevPage:
    if (!g_UseDisplay)
    {
        return
    }

    ControlFocus, %g_DisplayArea%
    Send, {pgup}
    ControlFocus, %g_InputArea%
return

ActivateRunZ:
;~ 晓亮修改 20210306
    ;~ Gui, Show, , % g_WindowName
    Gui, Show, % windowY " w" border * 2 + g_SkinConf.WidgetWidth
    . " h" windowHeight hideWindow, % g_WindowName
    if (g_Conf.Config.SwitchToEngIME)
    {
        SwitchToEngIME()
    }
return

ToggleWindow:
    if (WinActive(g_WindowName))
    {
        if (!g_Conf.Config.KeepInputText)
        {
            ControlSetText, %g_InputArea%, , %g_WindowName%
        }

        Gui, Hide
    }
    else
    {
        GoSub, ActivateRunZ
    }
return

getMouseCurrentLine()
{
    MouseGetPos, , mouseY, , classnn,
    if (classnn != g_DisplayArea)
    {
        return -1
    }

    ControlGetPos, , y, , h, %g_DisplayArea%
    lineHeight := h / g_DisplayRows
    index := Ceil((mouseY - y) / lineHeight)
    return index
}

ClickFunction:
    if (g_UseDisplay)
    {
        return
    }

    index := getMouseCurrentLine()
    if (index < 0)
    {
        return
    }

    if (g_CurrentCommandList[index] != "")
    {
        ChangeCommand(index - 1, true)
    }

    ControlFocus, %g_InputArea%
    Send, {end}

    if (g_Conf.Config.ClickToRun)
    {
        GoSub, RunCurrentCommand
    }
return

OpenContextMenu:
    if (!g_UseDisplay)
    {
        currentCommandText := ""
        if (!g_CurrentLine > 0)
        {
            currentCommandText .= Chr(g_FirstChar)
        }
        else
        {
            currentCommandText .= Chr(g_FirstChar + g_CurrentLine - 1)
        }
        Menu, ContextMenu, Add, %currentCommandText%>  运行 &Z, RunCurrentCommand
        Menu, ContextMenu, Add
    }

    Menu, ContextMenu, Add, 编辑配置 &E, EditConfig
    Menu, ContextMenu, Add, 重建索引 &S, ReindexFiles
    Menu, ContextMenu, Add, 显示历史 &H, DisplayHistoryCommands
    Menu, ContextMenu, Add, 更新路径 &C, ChangePath
    Menu, ContextMenu, Add
    Menu, ContextMenu, Add, 显示帮助 &A, Help
    Menu, ContextMenu, Add, 重新启动 &R, RestartRunZ
    Menu, ContextMenu, Add, 退出程序 &X, ExitRunZ
    Menu, ContextMenu, Show
    Menu, ContextMenu, DeleteAll
return

TabFunction:
    ControlGetFocus, ctrl,
    if (ctrl == g_InputArea)
    {
        ; 定位到一个隐藏编辑框
        ControlFocus, Edit2
    }
    else
    {
        ControlFocus, %g_InputArea%
    }
return

EscFunction:
    ToolTip
    if (g_Conf.Config.ClearInputWithEsc && g_CurrentInput != "")
    {
        GoSub, ClearInput
    }
    else
    {
        if (!g_Conf.Config.KeepInputText)
        {
            ControlSetText, %g_InputArea%, , %g_WindowName%
        }
        GoSub, HideOrExit
    }
return

HideOrExit:
    ; 如果是后台运行模式,只关闭窗口,不退出程序
    if (g_Conf.Config.RunInBackground)
    {
        Gui, Hide
    }
    else
    {
        GoSub, ExitRunZ
    }
return

NextCommand:
    if (g_UseDisplay)
    {
        ControlFocus, %g_DisplayArea%
        Send {down}
        return
    }
    ChangeCommand(1)
return

PrevCommand:
    if (g_UseDisplay)
    {
        ControlFocus, %g_DisplayArea%
        Send {up}
        return
    }
    ChangeCommand(-1)
return

GotoCommand:
    ControlGetFocus, ctrl,
    if (ctrl == g_InputArea)
    {
        return
    }

    index := Asc(SubStr(A_ThisHotkey, 0, 1)) - g_FirstChar + 1

    if (g_CurrentCommandList[index] != "")
    {
        ChangeCommand(index - 1, true)
    }
return

ChangeCommand(step, resetCurrentLine = false)
{
    ControlGetText, g_CurrentInput, %g_InputArea%

    if (resetCurrentLine
        || (SubStr(g_CurrentInput, 1, 1) != "@" && SubStr(g_CurrentInput, 1, 2) != "|@"))
    {
        g_CurrentLine := 1
    }

    row := g_CurrentCommandList.Length()
    if (row > g_DisplayRows)
    {
        row := g_DisplayRows
    }

    g_CurrentLine := Mod(g_CurrentLine + step, row)
    if (g_CurrentLine == 0)
    {
        g_CurrentLine := row
    }

    ; 重置当前命令
    g_CurrentCommand := g_CurrentCommandList[g_CurrentLine]

    ; 修改输入框内容
    currentChar := Chr(g_FirstChar + g_CurrentLine - 1)
    if (SubStr(g_CurrentInput, 1, 1) == "|")
    {
        newInput := "|@" currentChar " "
    }
    else
    {
        newInput := "@" currentChar " "
    }

    if (g_UseFallbackCommands)
    {
        if (SubStr(g_CurrentInput, 1, 1) == "@")
        {
            newInput .= SubStr(g_CurrentInput, 4)
        }
        else
        {
            newInput .= g_CurrentInput
        }
    }

    ControlGetText, result, %g_DisplayArea%
    result := StrReplace(result, ">| ", " | ")
    if (currentChar == Chr(g_FirstChar))
    {
        result := currentChar ">" SubStr(result, 3)
    }
    else
    {
        result := StrReplace(result, "`r`n" currentChar " | ", "`r`n" currentChar ">| ")
    }

    DisplaySearchResult(result)

    ControlSetText, %g_InputArea%, %newInput%, %g_WindowName%
    Send, {end}
}

GuiClose()
{
    if (!g_Conf.Config.RunInBackground)
    {
        GoSub, ExitRunZ
    }
}

SaveAutoConf()
{
    if (g_Conf.Config.SaveInputText)
    {
        g_AutoConf.DeleteKey("Auto", "InputText")
        g_AutoConf.AddKey("Auto", "InputText", g_CurrentInput)
    }

    if (g_Conf.Config.SaveHistory)
    {
        g_AutoConf.DeleteSection("History")
        g_AutoConf.AddSection("History")

        for index, element in g_HistoryCommands
        {
            if (element != "")
            {
                g_AutoConf.AddKey("History", index, element)
            }
        }
    }

    Loop
    {
        g_AutoConf.Save()

        if (!FileExist(g_AutoConfFile))
        {
            MsgBox, 配置文件 %g_AutoConfFile% 写入后丢失,请检查磁盘并点确定来重试
        }
        else
        {
            break
        }
    }
}

ExitRunZ:
    SaveAutoConf()
    ExitApp
return

GenerateSearchFileList()
{
    FileDelete, %g_SearchFileList%

    searchFileType := g_Conf.Config.SearchFileType

    for dirIndex, dir in StrSplit(g_Conf.Config.SearchFileDir, " | ")
    {
        if (InStr(dir, "A_") == 1)
        {
            searchPath := %dir%
        }
        else
        {
            searchPath := dir
        }

        for extIndex, ext in StrSplit(searchFileType, " | ")
        {
            Loop, Files, %searchPath%%ext%, R
            {
                if (g_Conf.Config.SearchFileExclude != ""
                        && RegExMatch(A_LoopFileLongPath, g_Conf.Config.SearchFileExclude))
                {
                    continue
                }
                FileAppend, file | %A_LoopFileLongPath%`n, %g_SearchFileList%,
            }
        }
    }
}

ReindexFiles:
    if (WinActive(g_WindowName))
    {
        ToolTip, 正在重建索引,请稍后...
    }

    GenerateSearchFileList()

    GoSub, CleanupRank

    if (WinActive(g_WindowName))
    {
        ToolTip, 重建索引完毕
        SetTimer, RemoveToolTip, 800
    }
return

EditConfig:
    if (g_Conf.Config.Editor != "")
    {
        Run, % g_Conf.Config.Editor " """ g_ConfFile """"
    }
    else
    {
        Run, % g_ConfFile
    }
return

EditAutoConfig:
    if (g_Conf.Config.Editor != "")
    {
        Run, % g_Conf.Config.Editor " """ g_AutoConfFile """"
    }
    else
    {
        Run, % g_AutoConfFile
    }
return


ProcessInputCommand:
    ControlGetText, g_CurrentInput, %g_InputArea%

    ; 如果使用异步的方式,TurnOnResultFilter 后会出问题,先绕一下
    if (SubStr(g_CurrentInput, 0, 1) == " ")
    {
        GoSub, ProcessInputCommandCallBack
        return
    }

    ; 为了避免搜索时间过长导致不再调用 ProcessInputCommand
    ; 不清楚这样做是否有其他问题
    SetTimer, ProcessInputCommandCallBack, 0
return

ProcessInputCommandCallBack:
    SetTimer, ProcessInputCommandCallBack, Off

    if (g_SkinConf.ShowInputBoxOnlyIfEmpty)
    {
        if (g_CurrentInput != "")
        {
            if (g_SkinConf.ShowCurrentCommand)
            {
                windowHeight := g_SkinConf.BorderSize * 4
                    + g_SkinConf.EditHeight * 2 + g_SkinConf.DisplayAreaHeight
            }
            else
            {
                windowHeight := g_SkinConf.BorderSize * 3
                    + g_SkinConf.EditHeight + g_SkinConf.DisplayAreaHeight
            }
            WinMove, %g_WindowName%, , , , , %windowHeight%
        }
        else
        {
            windowHeight := g_SkinConf.BorderSize * 2 + g_SkinConf.EditHeight
            WinMove, %g_WindowName%, , , , , %windowHeight%
        }

        if (g_SkinConf.RoundCorner > 0)
        {
            WinSet, Region, % "0-0 w" border * 2 + g_SkinConf.WidgetWidth " h" windowHeight
                . " r" g_SkinConf.RoundCorner "-" g_SkinConf.RoundCorner, % g_WindowName
        }
    }

    SearchCommand(g_CurrentInput)
return

SearchCommand(command = "", firstRun = false)
{
    g_UseDisplay := false
    g_ExecInterval := -1
    result := ""
    ; 供去重使用
    fullResult := ""
    static resultToFilter := ""
    commandPrefix := SubStr(command, 1, 1)

    if (commandPrefix == ";" || commandPrefix == ":")
    {
        g_UseResultFilter := false
        g_UseRealtimeExec := false
        resultToFilter := ""
        g_PipeArg := ""

        if (commandPrefix == ";")
        {
            g_CurrentCommand := g_FallbackCommands[1]
        }
        else if (commandPrefix == ":")
        {
            g_CurrentCommand := g_FallbackCommands[2]
        }

        g_CurrentCommandList := Object()
        g_CurrentCommandList.Push(g_CurrentCommand)
        result .= Chr(g_FirstChar) ">| "
            . StrReplace(g_CurrentCommand, "function | ", "功能 | ")
        DisplaySearchResult(result)
        return result
    }
    else if (commandPrefix == "|" && Arg != "")
    {
        ; 记录管道参数
        if (g_PipeArg == "")
        {
            g_PipeArg := Arg
        }
        ; 去掉 |,然后按常规搜索处理
        command := SubStr(command, 2)
        if (SubStr(command, 1, 1) == "@")
        {
            command := SubStr(command, 1, 4)
            return
        }
    }
    else if (InStr(command, " ") && g_CurrentCommand != "")
    {
        g_PipeArg := ""

        ; 输入包含空格时锁定搜索结果

        if (g_UseResultFilter)
        {
            if (resultToFilter == "")
            {
                ControlGetText, resultToFilter, %g_DisplayArea%
            }

            ; 取出空格后边的参数
            needle := SubStr(g_CurrentInput, InStr(g_CurrentInput, " ") + 1)
            DisplayResult(FilterResult(resultToFilter, needle))
        }
        else if (g_UseRealtimeExec)
        {
            RunCommand(g_CurrentCommand)
            resultToFilter := ""
        }
        else
        {
            resultToFilter := ""
        }

        return
    }
    else if (commandPrefix == "@")
    {
        g_UseResultFilter := false
        g_UseRealtimeExec := false
        resultToFilter := ""

        ; 搜索结果被锁定,直接退出
        return
    }

    g_UseResultFilter := false
    g_UseRealtimeExec := false
    resultToFilter := ""

    if (commandPrefix != "|")
    {
        g_PipeArg := ""
    }

    g_CurrentCommandList := Object()

    order := g_FirstChar

    for index, element in g_Commands
    {
        if (InStr(fullResult, element "`n") || inStr(g_ExcludedCommands, element "`n"))
        {
            continue
        }

        splitedElement := StrSplit(element, " | ")

        if (splitedElement[1] == "file")
        {
            SplitPath, % splitedElement[2], fileName, fileDir, , fileNameNoExt

            ; 只搜索和展示不带扩展名的文件名
            elementToSearch := fileNameNoExt
            if (g_Conf.Config.ShowFileExt)
            {
                elementToShow := "file | " . fileName " | " splitedElement[3]
            }
            else
            {
                elementToShow := "file | " . fileNameNoExt " | " splitedElement[3]
            }


            if (splitedElement.Length() >= 3)
            {
                elementToSearch .= " " . splitedElement[3]
            }

            if (g_Conf.Config.SearchFullPath)
            {
                ; TCMatch 在搜索路径时只搜索文件名,强行将  转成空格
                elementToSearch := StrReplace(fileDir, "", " ") . " " . elementToSearch
            }
        }
        else
        {
            elementToShow := splitedElement[1] " | " splitedElement[2]
            elementToSearch := StrReplace(splitedElement[2], "/", " ")
            elementToSearch := StrReplace(elementToSearch, "", " ")

            if (splitedElement.Length() >= 3)
            {
                elementToShow .= " | " splitedElement[3]
                elementToSearch .= " " . splitedElement[3]
            }
        }

        if (command == "" || MatchCommand(elementToSearch, command))
        {
            fullResult .= element "`n"
            g_CurrentCommandList.Push(element)

            if (order == g_FirstChar)
            {
                g_CurrentCommand := element
                result .= Chr(order++) . ">| " . elementToShow
            }
            else
            {
                result .= "`n" Chr(order++) . " | " . elementToShow
            }

            if (order - g_FirstChar >= g_DisplayRows)
            {
                break
            }
            ; 第一次运行只加载 function 类型
            if (firstRun && (order - g_FirstChar >= g_DisplayRows - 4))
            {
                result .= "`n`n现有 " g_Commands.Length() " 条搜索项。"
                result .= "`n`n键入内容 搜索,回车 执行当前命令,Alt + 字母 执行,F1 帮助,Esc 关闭。"

                break
            }
        }
    }

    if (result == "")
    {
        if (IsLabel("Calc") && Eval(g_CurrentInput) != 0)
        {
            DisplayResult(Eval(g_CurrentInput))
            return
        }

        g_UseFallbackCommands := true
        g_CurrentCommand := g_FallbackCommands[1]
        g_CurrentCommandList := g_FallbackCommands

        for index, element in g_FallbackCommands
        {
            if (index == 1)
            {
                result .= Chr(g_FirstChar - 1 + index++) . ">| " element
            }
            else
            {
                result .= "`n"
                result .= Chr(g_FirstChar - 1 + index++) . " | " element
            }
        }
    }
    else
    {
        g_UseFallbackCommands := false
    }

    if (g_SkinConf.HideCol2)
    {
        result := StrReplace(result, "file | ")
        result := StrReplace(result, "function | ")
        result := StrReplace(result, "cmd | ")
        result := StrReplace(result, "url | ")
    }
    else
    {
        result := StrReplace(result, "file | ", "文件 | ")
        result := StrReplace(result, "function | ", "功能 | ")
        result := StrReplace(result, "cmd | ", "命令 | ")
        result := StrReplace(result, "url | ", "网址 | ")
    }

    DisplaySearchResult(result)
    return result
}

DisplaySearchResult(result)
{
    DisplayControlText(result)

    if (g_CurrentCommandList.Length() == 1 && g_Conf.Config.RunIfOnlyOne)
    {
        RunCommand(g_CurrentCommand)
    }

    if (g_SkinConf.ShowCurrentCommand)
    {
        commandToShow := SubStr(g_CurrentCommand, InStr(g_CurrentCommand, " | ") + 3)
        ControlSetText, %g_CommandArea%, %commandToShow%, %g_WindowName%
    }
}

FilterResult(text, needle)
{
    result := ""
    Loop, Parse, text, `n, `r
    {
        if (!InStr(A_LoopField, " | ") && MatchResult(A_LoopField, needle))
        {
            result .= A_LoopField "`n"
        }
        else if (MatchResult(StrReplace(SubStr(A_LoopField, 5), "", " "), needle))
        {
            result .= A_LoopField "`n"
        }
    }

    return result
}

TurnOnResultFilter()
{
    if (!g_UseResultFilter)
    {
        g_UseResultFilter := true

        if (!InStr(g_CurrentInput, " "))
        {
            ControlFocus, %g_InputArea%
            Send, {space}
        }
    }
}

TurnOnRealtimeExec()
{
    if (!g_UseRealtimeExec)
    {
        g_UseRealtimeExec := true

        if (!InStr(g_CurrentInput, " "))
        {
            ControlFocus, %g_InputArea%
            Send, {space}
        }
    }
}

SetExecInterval(second)
{
    ; g_ExecInterval 为 0 时,表示可以进入间隔运行状态
    ; g_ExecInterval 为 -1 时,表示状态以被打破,需要退出
    if (g_ExecInterval >= 0)
    {
        g_ExecInterval := second * 1000
        return true
    }
    else
    {
        SetTimer, %g_LastExecLabel%, Off
        return false
    }
}

ClearInput:
    ClearInput()
return

; 给插件用的函数
ClearInput()
{
    ControlSetText, %g_InputArea%, , %g_WindowName%
    ControlFocus, %g_InputArea%
}

RunCurrentCommand:
    if (GetInputState() == 1)
    {
        Send, {enter}
    }

    RunCommand(g_CurrentCommand)
return

ParseArg:
    if (g_PipeArg != "")
    {
        Arg := g_PipeArg
        return
    }

    commandPrefix := SubStr(g_CurrentInput, 1, 1)

    ; 分号或者冒号的情况,直接取命令为参数
    if (commandPrefix == ";" || commandPrefix == ":")
    {
        Arg := SubStr(g_CurrentInput, 2)
        return
    }
    else if (commandPrefix == "@")
    {
        ; 处理调整过顺序的命令
        Arg := SubStr(g_CurrentInput, 4)
        return
    }

    ; 用空格来判断参数
    if (InStr(g_CurrentInput, " ") && !g_UseFallbackCommands)
    {
        Arg := SubStr(g_CurrentInput, InStr(g_CurrentInput, " ") + 1)
    }
    else if (g_UseFallbackCommands)
    {
        Arg := g_CurrentInput
    }
    else
    {
        Arg := ""
    }
return

MatchCommand(Haystack, Needle)
{
    if (g_EnableTCMatch)
    {
        return TCMatch(Haystack, Needle)
    }

    return InStr(Haystack, Needle)
}

MatchResult(Haystack, Needle)
{
    if (g_EnableTCMatch)
    {
        return TCMatch(Haystack, Needle)
    }

    return InStr(Haystack, Needle)
}

RunCommand(originCmd)
{
    GoSub, ParseArg

    g_UseDisplay := false
    g_DisableAutoExit := true
    g_ExecInterval := 0

    splitedOriginCmd := StrSplit(originCmd, " | ")
    cmd := splitedOriginCmd[2]

    if (splitedOriginCmd[1] == "file")
    {
        if (InStr(cmd, ".lnk"))
        {
            ; 处理 32 位 ahk 运行不了某些 64 位系统 .lnk 的问题
            FileGetShortcut, %cmd%, filePath
            if (!FileExist(filePath))
            {
                filePath := StrReplace(filePath, "C:Program Files (x86)", "C:Program Files")
                if (FileExist(filePath))
                {
                    cmd := filePath
                }
            }
        }

        if (Arg == "")
        {
            Run, %cmd%
        }
        else
        {
            Run, %cmd% "%Arg%"
        }
    }
    else if (splitedOriginCmd[1] == "function")
    {
        ; 第四个参数是参数
        if (splitedOriginCmd.Length() >= 4)
        {
            Arg := splitedOriginCmd[4]
        }

        if (IsLabel(cmd))
        {
            GoSub, %cmd%
        }
    }
    else if (splitedOriginCmd[1] == "cmd")
    {
        RunWithCmd(cmd)
    }
    else if (splitedOriginCmd[1] == "url")
    {
        url := splitedOriginCmd[2]
        if (!Instr(url, "http"))
        {
            url := "http://" . url
        }

        Run, %url%
    }

    if (g_Conf.Config.SaveHistory && cmd != "DisplayHistoryCommands")
    {
        if (splitedOriginCmd.Length() == 3 && Arg != "")
        {
            g_HistoryCommands.InsertAt(1, originCmd " | " Arg)
        }
        else if (originCmd != "")
        {
            g_HistoryCommands.InsertAt(1, originCmd)
        }

        if (g_HistoryCommands.Length() > g_Conf.Config.HistorySize)
        {
            g_HistoryCommands.Pop()
        }
    }

    if (g_Conf.Config.AutoRank)
    {
        ChangeRank(originCmd)
    }

    g_DisableAutoExit := false

    if (g_Conf.Config.RunOnce && !g_UseDisplay)
    {
        if (!g_Conf.Config.KeepInputText)
        {
            GoSub, ClearInput
        }
        GoSub, HideOrExit
    }

    if (g_ExecInterval > 0 && splitedOriginCmd[1] == "function")
    {
        SetTimer, %cmd%, %g_ExecInterval%
        g_LastExecLabel := cmd
    }

    g_PipeArg := ""
    FullPipeArg := ""
}

ChangeRank(cmd, show = false, inc := 1)
{
    splitedCmd := StrSplit(cmd, " | ")

    if (splitedCmd.Length() >= 4 && splitedCmd[1] == "function")
    {
        ; 去掉参数
        cmd := splitedCmd[1]  " | " splitedCmd[2] " | " splitedCmd[3]
    }

    cmdRank := g_AutoConf.GetValue("Rank", cmd)
    if cmdRank is integer
    {
        g_AutoConf.DeleteKey("Rank", cmd)
        cmdRank += inc
    }
    else
    {
        cmdRank := inc
    }

    if (cmdRank != 0 && cmd != "")
    {
        ; 如果将到负数,都设置成 -1,然后屏蔽
        if (cmdRank < 0)
        {
            cmdRank := -1
            g_ExcludedCommands .= cmd "`n"
        }

        g_AutoConf.AddKey("Rank", cmd, cmdRank)
    }
    else
    {
        cmdRank := 0
    }

    if (show)
    {
        ToolTip, 调整 %cmd% 的权重到 %cmdRank%
        SetTimer, RemoveToolTip, 800
    }
}

; 比较耗时,必要时才使用,也可以手动编辑 RunZ.auto.ini
CleanupRank:
    ; 先把 g_Commands 里的 Rank 信息清掉
    LoadFiles(false)

    for command, rank in g_AutoConf.Rank
    {
        cleanup := true
        for index, element in g_Commands
        {
            if (InStr(element, command) == 1)
            {
                cleanup := false
                break
            }
        }
        if (cleanup)
        {
            g_AutoConf.DeleteKey("Rank", command)
        }
    }

    Loop
    {
        g_AutoConf.Save()

        if (!FileExist(g_AutoConfFile))
        {
            MsgBox, 配置文件 %g_AutoConfFile% 写入后丢失,请检查磁盘并点确定来重试
        }
        else
        {
            break
        }
    }

    LoadFiles()
return

RunSelectedCommand:
    if (SubStr(A_ThisHotkey, 1, 1) == "~")
    {
        ControlGetFocus, ctrl,
        if (ctrl == g_InputArea)
        {
            return
        }
    }

    index := Asc(SubStr(A_ThisHotkey, 0, 1)) - g_FirstChar + 1

    RunCommand(g_CurrentCommandList[index])
return

IncreaseRank:
    if (g_CurrentCommand != "")
    {
        ChangeRank(g_CurrentCommand, true)
        LoadFiles()
    }
return

DecreaseRank:
    if (g_CurrentCommand != "")
    {
        ChangeRank(g_CurrentCommand, true, -1)
        LoadFiles()
    }
return

LoadFiles(loadRank := true)
{
    g_Commands := Object()
    g_FallbackCommands := Object()

    if (loadRank)
    {
        rankString := ""
        for command, rank in g_AutoConf.Rank
        {
            if (StrLen(command) > 0)
            {
                if (rank >= 1)
                {
                    rankString .= rank "`t" command "`n"
                }
                else
                {
                    g_ExcludedCommands .= command "`n"
                }
            }
        }

        if (rankString != "")
        {
            Sort, rankString, R N

            Loop, Parse, rankString, `n
            {
                if (A_LoopField == "")
                {
                    continue
                }

                g_Commands.Push(StrSplit(A_LoopField, "`t")[2])
            }
        }
    }


    for key, value in g_Conf.Command
    {
        if (value != "")
        {
            g_Commands.Push(key . " | " . value)
        }
        else
        {
            g_Commands.Push(key)
        }
    }

    for index, element in g_Plugins
    {
        if (IsLabel(element))
        {
            GoSub, %element%
        }
        else
        {
            MsgBox, 未在 %A_ScriptDir%Plugins%element%.ahk 中发现 %element% 标签,请修改!
        }
    }

    g_FallbackCommands := Object()
    for key, value in g_Conf.FallbackCommand
    {
        if (IsLabel(StrSplit(key, " | ")[2]))
        {
            g_FallbackCommands.Push(key)
        }
    }

    if (g_FallbackCommands.Length() == 0)
    {
        g_FallbackCommands.Push("function | AhkRun | 使用 Ahk 的 Run() 运行")
    }

    if (FileExist(A_ScriptDir "ConfUserFunctionsAuto.txt"))
    {
        userFunctionLabel := "UserFunctionsAuto"
        if (IsLabel(userFunctionLabel))
        {
            GoSub, %userFunctionLabel%
        }
        else
        {
            MsgBox, 未在 %A_ScriptDir%ConfUserFunctionsAuto.txt 中发现 %userFunctionLabel% 标签,请修改!
        }
    }

    if (FileExist(g_UserFileList))
    {
        Loop, Read, %g_UserFileList%
        {
            g_Commands.Push(A_LoopReadLine)
        }
    }

    Loop, Read, %g_SearchFileList%
    {
        g_Commands.Push(A_LoopReadLine)
    }

    if (g_Conf.Config.LoadControlPanelFunctions)
    {
        Loop, Read, %A_ScriptDir%CoreControlPanelFunctions.txt
        {
            g_Commands.Push(A_LoopReadLine)
        }
    }
}

; 用来显示控制界面
DisplayControlText(text)
{
    ControlSetText, %g_DisplayArea%, % AlignText(text), %g_WindowName%
}

; 用来显示命令结果
DisplayResult(result := "")
{
    textToDisplay := StrReplace(result, "`n", "`r`n")
    ControlSetText, %g_DisplayArea%, %textToDisplay%, %g_WindowName%
    g_UseDisplay := true
    result := ""
    textToDisplay := ""
}

LoadHistoryCommands()
{
    historySize := g_Conf.Config.HistorySize

    index := 0
    for key, value in g_AutoConf.History
    {
        if (StrLen(value) > 0)
        {
            g_HistoryCommands.Push(value)
            index++

            if (index == historySize)
            {
                return
            }
        }
    }
}

DisplayHistoryCommands:
    g_UseDisplay := false
    result := ""
    g_CurrentCommandList := Object()
    g_CurrentLine := 1

    for index, element in g_HistoryCommands
    {
        if (index == 1)
        {
            result .= Chr(g_FirstChar + index - 1) . ">| "
            g_CurrentCommand := element
        }
        else
        {
            result .= Chr(g_FirstChar + index - 1) . " | "
        }

        splitedElement := StrSplit(element, " | ")

        result .= splitedElement[1] " | " splitedElement[2]
            . " | " splitedElement[3] " #参数: " splitedElement[4] "`n"

        g_CurrentCommandList.Push(element)
    }

    result := StrReplace(result, "file | ", "文件 | ")
    result := StrReplace(result, "function | ", "功能 | ")
    result := StrReplace(result, "cmd | ", "命令 | ")
    result := StrReplace(result, "url | ", "网址 | ")

    DisplayControlText(result)
return

; 第三个参数不再是 fallback,备用,为了兼容不改变第四个参数的含义
@(label, info, fallback = false, key = "")
{
    if (!IsLabel(label))
    {
        MsgBox, 未找到 %label% 标签,请检查 %A_ScriptDir%ConfUserFunctions.ahk 文件格式!
        return
    }

    g_Commands.Push("function | " . label . " | " . info )

    if (key != "")
    {
        Hotkey, %key%, %label%
    }
}

RunAndGetOutput(command)
{
    tempFileName := "RunZ.stdout.log"
    fullCommand = %ComSpec% /C "%command% > %tempFileName%"

    /*
    fullCommand = bash -c "%command% &> %tempFileName%"

    if (!FileExist("c:msys64usrbinbash.exe"))
    {
        fullCommand = %ComSpec% /C "%command% > %tempFileName%"
    }
    */

    RunWait, %fullCommand%, %A_Temp%, Hide
    FileRead, result, %A_Temp%%tempFileName%
    FileDelete, %A_Temp%%tempFileName%
    return result
}

RunWithCmd(command, onlyCmd = false)
{
    if (!onlyCmd && FileExist("c:msys64usrbinmintty.exe"))
    {
        Run, % "mintty -e sh -c '" command "; read'"
    }
    else
    {
        Run, % ComSpec " /C " command " & pause"
    }
}

OpenPath(filePath)
{
    if (!FileExist(filePath))
    {
        return
    }

    if (FileExist(g_Conf.Config.TCPath))
    {
        TCPath := g_Conf.Config.TCPath
        Run, %TCPath% /O /A /L="%filePath%"
    }
    else
    {
        SplitPath, filePath, , fileDir, ,
        Run, explorer "%fileDir%"
    }
}

GetAllFunctions()
{
    result := ""

    for index, element in g_Commands
    {
        if (InStr(element, "function | ") == 1 and !InStr(result, element "`n"))
        {
            result .= "* | " element "`n"
        }
    }

    result := StrReplace(result, "function | ", "功能 | ")

    return AlignText(result)
}

OpenCurrentFileDir:
    filePath := StrSplit(g_CurrentCommand, " | ")[2]
    OpenPath(filePath)
return

DeleteCurrentFile:
    filePath := StrSplit(g_CurrentCommand, " | ")[2]

    if (!FileExist(filePath))
    {
        return
    }

    FileRecycle, % filePath
    GoSub, ReindexFiles
return

ShowCurrentFile:
    clipboard := StrSplit(g_CurrentCommand, " | ")[2]
    ToolTip, % clipboard
    SetTimer, RemoveToolTip, 800
return

RemoveToolTip:
    ToolTip
    SetTimer, RemoveToolTip, Off
return


WM_MOUSEMOVE(wParam, lParam)
{
    if (wparam = 1) ; LButton
    {
        PostMessage, 0xA1, 2, , , A ; WM_NCLBUTTONDOWN
    }

    if (!g_Conf.Config.ChangeCommandOnMouseMove)
    {
        return
    }

    MouseGetPos, , mouseY, , classnn,
    if (classnn != g_DisplayArea)
    {
        return -1
    }

    ControlGetPos, , y, , h, %g_DisplayArea%
    lineHeight := h / g_DisplayRows
    index := Ceil((mouseY - y) / lineHeight)

    if (g_CurrentCommandList[index] != "")
    {
        ChangeCommand(index - 1, true)
    }
}

WM_ACTIVATE(wParam, lParam)
{
    if (g_DisableAutoExit)
    {
        return
    }

    if (wParam >= 1) ; 窗口激活
    {
        return
    }
    else if (wParam <= 0) ; 窗口非激活
    {
        SetTimer, ToExit, 50
    }
}

ToExit:
    if (!WinExist("RunZ.ahk"))
    {
        if (!g_Conf.Config.KeepInputText)
        {
            ControlSetText, %g_InputArea%, , %g_WindowName%
        }

        GoSub, HideOrExit
    }

    SetTimer, ToExit, Off
return

KeyHelpText()
{
    return AlignText(""
    . "* | 按键 | Shift + F1 | 显示置顶的按键提示`n"
    . "* | 按键 | Alt + F4   | 退出置顶的按键提示`n"
    . "* | 按键 | 回车       | 执行当前命令`n"
    . "* | 按键 | Esc        | 关闭窗口`n"
    . "* | 按键 | Alt +      | 加每列行首字符执行`n"
    . "* | 按键 | Tab +      | 再按每列行首字符执行`n"
    . "* | 按键 | Tab +      | 再按 Shift + 行首字符 定位`n"
    . "* | 按键 | Win  + j   | 显示或隐藏窗口`n"
    . "* | 按键 | Ctrl + j   | 移动到下一条命令`n"
    . "* | 按键 | Ctrl + k   | 移动到上一条命令`n"
    . "* | 按键 | Ctrl + f   | 在输出结果中翻到下一页`n"
    . "* | 按键 | Ctrl + b   | 在输出结果中翻到上一页`n"
    . "* | 按键 | Ctrl + h   | 显示历史记录`n"
    . "* | 按键 | Ctrl + n   | 可增加当前功能的权重`n"
    . "* | 按键 | Ctrl + p   | 可减少当前功能的权重`n"
    . "* | 按键 | Ctrl + l   | 清除编辑框内容`n"
    . "* | 按键 | Ctrl + r   | 重新创建待搜索文件列表`n"
    . "* | 按键 | Ctrl + q   | 重启`n"
    . "* | 按键 | Ctrl + d   | 用 TC 打开第一个文件所在目录`n"
    . "* | 按键 | Ctrl + s   | 显示并复制当前文件的完整路径`n"
    . "* | 按键 | Ctrl + x   | 删除当前文件`n"
    . "* | 按键 | Ctrl + i   | 移动光标当行首`n"
    . "* | 按键 | Ctrl + o   | 移动光标当行尾`n"
    . "* | 按键 | F2         | 编辑配置文件`n"
    . "* | 按键 | F3         | 编辑自动写入的配置文件`n"
    . "* | 功能 | 输入网址   | 可直接输入 www 或 http 开头的网址`n"
    . "* | 功能 | `;         | 以分号开头命令,用 ahk 运行`n"
    . "* | 功能 | :          | 以冒号开头的命令,用 cmd 运行`n"
    . "* | 功能 | 无结果     | 搜索无结果,回车用 ahk 运行`n"
    . "* | 功能 | 空格       | 输入空格后,搜索内容锁定")
}

UpdateSendTo(create = true, overwrite = false)
{
    lnkFilePath := StrReplace(A_StartMenu, "Start Menu", "SendTo") "RunZ.lnk"

    if (!create)
    {
        FileDelete, %lnkFilePath%
        return
    }

    if (!overwrite && FileExist(lnkFilePath))
    {
        return
    }

    FileCreateShortcut, % A_ScriptDir "RunZ.exe", % A_ScriptDir "CoreSendToRunZ.lnk"
        , , "%A_ScriptDir%CoreRunZCmdTool.ahk", 发送到 RunZ, % A_ScriptDir "RunZ.ico"
    FileCopy, % A_ScriptDir "CoreSendToRunZ.lnk"
        , % StrReplace(A_StartMenu, "Start Menu", "SendTo") "RunZ.lnk", 1
}

UpdateStartupLnk(create = true, overwrite = false)
{
    lnkFilePath := A_Startup "RunZ.lnk"

    if (!create)
    {
        FileDelete, %lnkFilePath%
        return
    }

    if (!FileExist(lnkFilePath) || overwrite)
    {
        FileCreateShortcut, % A_ScriptDir "RunZ.exe", %lnkFilePath%
            , %A_ScriptDir%, RunZ.ahk --hide, RunZ, % A_ScriptDir "RunZ.ico"
    }
}

ChangePath:
    UpdateSendTo(g_Conf.Config.CreateSendToLnk, true)
    UpdateStartupLnk(g_Conf.Config.CreateStartupLnk, true)
return

AlignText(text)
{
    col3MaxLen := g_SkinConf.DisplayCol3MaxLength
    col4MaxLen := g_SkinConf.DisplayCol4MaxLength
    col3Pos := 10

    StrSpace := " "
    Loop, % col3MaxLen + col4MaxLen
        StrSpace .= " "

    result := ""

    if (g_SkinConf.HideCol2)
    {
        ; 隐藏第二列的话,把第二列的空间分给第三列
        col3MaxLen += 7
        col3Pos := 5

        hasCol2 := true
        Loop, Parse, text, `n, `r
        {
            if (SubStr(text, 3, 1) != "|" || SubStr(text, 8, 1) != "|")
            {
                hasCol2 := false
                break
            }
        }

        if (hasCol2)
        {
            col3Pos := 10
        }
    }

    if (g_SkinConf.HideCol4IfEmpty)
    {
        Loop, Parse, text, `n, `r
        {
            if (StrSplit(SubStr(A_LoopField, col3Pos), " | ")[2] != "")
            {
                hasCol4 := true
                break
            }
        }

        if (!hasCol4)
        {
            ; 加上中间的 " | "
            col3MaxLen += col4MaxLen + 3
            col4MaxLen := 0
        }
    }

    Loop, Parse, text, `n, `r
    {
        if (!InStr(A_LoopField, " | "))
        {
            result .= A_LoopField "`r`n"
            continue
        }

        if (hasCol2)
        {
            ; 内容包含第二列,需要去掉
            result .= SubStr(A_LoopField, 1, 4)
        }
        else
        {
            result .= SubStr(A_LoopField, 1, col3Pos - 1)
        }

        splitedLine := StrSplit(SubStr(A_LoopField, col3Pos), " | ")
        col3RealLen := StrLen(RegExReplace(splitedLine[1], "[^x00-xff]", "`t`t"))

        if (col3RealLen > col3MaxLen)
        {
            result .= SubStrByByte(splitedLine[1], col3MaxLen)
        }
        else
        {
            result .= splitedLine[1] . SubStr(StrSpace, 1, col3MaxLen - col3RealLen)
        }

        if (col4MaxLen > 0)
        {
            result .= " | "

            col4RealLen := StrLen(RegExReplace(splitedLine[2], "[^x00-xff]", "`t`t"))

            if (col4RealLen > col4MaxLen)
            {
                result .= SubStrByByte(splitedLine[2], col4MaxLen)
            }
            else
            {
                result .= splitedLine[2]
            }
        }

        result .= "`r`n"
    }

    return result
}

WatchUserFileList:
    FileGetTime, newUserFileListModifyTime, %g_UserFileList%
    if (newUserFileListModifyTime == "")
    {
        FileAppend, , %g_UserFileList%
    }

    if (lastUserFileListModifyTime != "" && lastUserFileListModifyTime != newUserFileListModifyTime)
    {
        LoadFiles()
    }
    lastUserFileListModifyTime := newUserFileListModifyTime

    FileGetTime, newConfFileModifyTime, %g_ConfFile%
    if (lastConfFileModifyTime != "" && lastConfFileModifyTime != newConfFileModifyTime)
    {
        GoSub, RestartRunZ
    }
    lastConfFileModifyTime := newConfFileModifyTime
return

SaveResultAsArg:
    Arg := ""
    ControlGetText, result, %g_DisplayArea%

    ; 处理隐藏第二列的情况
    if (g_SkinConf.HideCol2)
    {
        FullPipeArg := ""
        Loop, Parse, result, `n, `r
        {
            FullPipeArg .= SubStr(A_LoopField, 1, 2) "| 占位 | " SubStr(A_LoopField, 5) "`n"
        }
    }
    else
    {
        FullPipeArg := result
    }

    if (InStr(g_CurrentCommand, "file | ") == 1)
    {
        Arg .= StrSplit(g_CurrentCommand, " | ")[2]
    }
    else if (!InStr(result, " | "))
    {
        Arg .= StrReplace(result, "`n", " ")
        Arg := StrReplace(Arg, "`r")
    }
    else
    {
        if (g_SkinConf.HideCol2)
        {
            Loop, Parse, result, `n, `r
            {
                Arg .= Trim(StrSplit(A_LoopField, " | ")[2]) " "
            }
        }
        else
        {
            Loop, Parse, result, `n, `r
            {
                Arg .= Trim(StrSplit(A_LoopField, " | ")[3]) " "
            }
        }
    }

    Arg := Trim(Arg)

    ControlFocus, %g_InputArea%
    ControlSetText, %g_InputArea%, |
    Send, {End}
    if (g_CommandFilter != "")
    {
        ; 第一个 | 代表要用管道执行,不然 g_PipeArg 会被清空
        SearchCommand("|" g_CommandFilter)
        g_CommandFilter := ""
    }
return

; 格式:
; 与 command1&command2
; 或 command1|command2
; 非 !command1
SetCommandFilter(command)
{
    g_CommandFilter := command
}

Help:
    DisplayResult(KeyHelpText() . GetAllFunctions())
return

KeyHelp:
    ToolTip, % KeyHelpText()
    SetTimer, RemoveToolTip, 5000
return


#include %A_ScriptDir%LibEasyIni.ahk
#include %A_ScriptDir%LibTCMatch.ahk
#include %A_ScriptDir%CoreCommon.ahk
#include %A_ScriptDir%CoreGlobalMenu.ahk
#include *i %A_ScriptDir%CorePlugins.ahk
; 发送到菜单自动生成的命令
#include *i %A_ScriptDir%ConfUserFunctionsAuto.txt

 

为了实现无窗口静默添加AutoHotkey的鼠标右键中文菜单,MenuSetup.ahk只好也修改一下

/*
AutoHotkey 版本: 1.x
操作系统:    WinXP
作者:        甲壳虫<jdchenjian@gmail.com>
博客:        http://hi.baidu.com/jdchenjian
脚本说明:   此工具用来修改 AutoHotkey 脚本的右键菜单关联,适用于 AutoHotkey 安装版、绿色版。
脚本版本:   2009-01-21

修改作者:	兔子
更新说明:
2010.01.09	之前某个时间,修改AHK路径、编辑器路径、编译器路径,默认全部在当前目录下寻找
2010.01.09	去掉默认在新建菜单的勾
2010.06.21	如果SCITE为默认编辑器,则复制个人配置文件“SciTEUser.properties”到%USERPROFILE%
2010.06.25	修正因#NoEnv使%USERPROFILE%变量直接引用无效
2016.04.18	删除“2010.06.21”的改动
*/

; --- 20190207 晓亮修改 ---

#NoEnv
#SingleInstance, force
SendMode Input
SetWorkingDir %A_ScriptDir%

; 版本(仅用于显示)
Script_Version=v1.0.3.2

; AutoHotkey 原版的相关信息写在注册表HKCR主键中,
; 尝试是当前用户否有权操作该键,如果无权操作HKCR键(受限用户),
; 可通过操作注册表HKCU键来实现仅当前用户关联AHK脚本。
IsLimitedUser:=0
RegWrite, REG_SZ, HKCR, .test
if ErrorLevel
	IsLimitedUser:=1
RegDelete, HKCR, .test
if ErrorLevel
	IsLimitedUser:=1

if IsLimitedUser=0 ; 非受限用户操作HKCR键
{
	RootKey=HKCR
	Subkey=
}
else ; 受限用户操作HKCU键
{
	RootKey=HKCU
	Subkey=SoftwareClasses ; <-- 为简化后面的脚本,此子键须以“”结尾
}

; 检查是否存在AHK注册表项
RegRead, FileType, %RootKey%, %Subkey%.ahk
if FileType<>
{
	RegRead, value, %RootKey%, %Subkey%%FileType%ShellOpenCommand ;AHK路径
	AHK_Path:=PathGetPath(value)
	RegRead, value, %RootKey%, %Subkey%%FileType%ShellEditCommand ;编辑器路径
	Editor_Path:=PathGetPath(value)
	RegRead, value, %RootKey%, %Subkey%%FileType%ShellCompileCommand ;编译器路径
	Compiler_Path:=PathGetPath(value)
	RegRead, Template_Name, %RootKey%, %Subkey%.ahkShellNew, FileName ;模板文件名
}
else
	FileType=AutoHotkeyScript

if AHK_Path=
{
	IfExist, %A_ScriptDir%AutoHotkey.exe
		AHK_path=%A_ScriptDir%AutoHotkey.exe
}

if Editor_Path=
{
	IfExist, %A_ScriptDir%SciTESciTE.exe
		Editor_Path=%A_ScriptDir%SciTESciTE.exe
}

if Compiler_Path=
{
	IfExist, %A_ScriptDir%CompilerAhk2Exe.exe
		Compiler_Path=%A_ScriptDir%CompilerAhk2Exe.exe
}

if Template_Name=
	Template_Name=Template.ahk

; --- 20190207 晓亮修改 ---
;设置AHK默认文件夹为  D:greenAutoHotkey
AHK_path=D:greenAutoHotkeyAutoHotkeyU32.exe
Editor_Path=D:greenAutoHotkeySciTESciTE.exe
Compiler_Path=D:greenAutoHotkeyCompilerAhk2Exe.exe

Gui, Add, Tab, x10 y10 w480 h250 Choose1, 设置|说明
	Gui, Tab, 1
		Gui, Add, GroupBox, x20 y40 w460 h50 , “运行脚本”关联的 AutoHotkey
		Gui, Add, Edit, x35 y60 w340 h20 vAHK_Path, %AHK_path%
		Gui, Add, Button, x385 y60 w40 h20 gFind_AHK, 浏览

		Gui, Add, GroupBox, x20 y100 w460 h50 , “编辑脚本”关联的编辑器
		Gui, Add, Edit, x35 y120 w340 h20 vEditor_Path, %Editor_Path%
		Gui, Add, Button, x385 y120 w40 h20 gChoose_Editor, 浏览
		Gui, Add, Button, x430 y120 w40 h20 gDefault_Editor, 默认

		Gui, Add, GroupBox, x20 y160 w460 h50 , “编译脚本”关联的编译器
		Gui, Add, Edit, x35 y180 w340 h20 vCompiler_Path, %Compiler_Path%
		Gui, Add, Button, x385 y180 w40 h20 gChoose_Compiler, 浏览
		Gui, Add, Button, x430 y180 w40 h20 gDefault_Compiler, 默认

		Gui, Add, Checkbox, x35 y230 w270 h20 gNew_Script vNew_Script, 右键“新建”菜单中增加“AutoHotkey 脚本”
		Gui, Add, Button, x310 y230 w80 h20 vEdit_Template gEdit_Template, 编辑脚本模板
		Gui, Add, Button, x400 y230 w80 h20 vDelete_Template gDelete_Template, 删除脚本模板

	Gui, Tab, 2
		Gui, Font, bold
		Gui, Add, Text,, AutoHotkey 脚本关联工具  ScriptSetting %Script_Version%
		Gui, Font
		Gui, Font, CBlue underline
		Gui, Add, Text, gWebsite, 作者:甲壳虫 <jdchenjian@gmail.com>`n`n博客:http://hi.baidu.com/jdchenjian
		Gui, Font
		Gui, Add, Text, w450, 此工具用来修改 AutoHotkey 脚本的右键菜单关联,适用于 AutoHotkey 安装版、绿色版。
		Gui, Add, Text, w450, 您可以用它来修改默认脚本编辑器、编译器,修改默认的新建脚本模板。设置后,在右键菜单中添加“运行脚本”、“编辑脚本”、“编译脚本”和“新建 AutoHotkey 脚本”等选项。
		Gui, Add, Text, w450, 要取消脚本的系统关联,请按“卸载”。注意:卸载后您将无法通过双击来运行脚本,也不能通过右键菜单来启动脚本编辑器...

Gui, Tab
Gui, Add, Button, x100 y270 w60 h20 Default gInstall, 设置
Gui, Add, Button, x200 y270 w60 h20 gUninstall, 卸载
Gui, Add, Button, x300 y270 w60 h20 gCancel, 取消

Gui, Show, x250 y200 h300 w500 CEnter, ScriptSetting %Script_Version%
GuiControl, Disable, Edit_Template ; 使“编辑脚本模板”按钮无效
IfNotExist, %A_WinDir%ShellNew%Template_Name%
	GuiControl, Disable, Delete_Template ; 使“删除脚本模板”按钮无效

; 当鼠标指向链接时,指针变成手形
hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
OnMessage(0x200,"WM_MOUSEMOVE")

; --- 20190207 晓亮修改 ---
goto,Install
return

; 改变鼠标指针为手形
WM_MOUSEMOVE(wParam,lParam)
{
	global hCurs
	MouseGetPos,,,,ctrl
	if ctrl in static2
		DllCall("SetCursor","UInt",hCurs)
	return
}
return

GuiClose:
GuiEscape:
Cancel:
	ExitApp

	; 查找 AutoHotkey 主程序
Find_AHK:
	Gui +OwnDialogs
	FileSelectFile, AHK_Path, 3, , 查找 AutoHotkey.exe, AutoHotkey.exe
	if AHK_Path<>
		GuiControl,,AHK_Path, %AHK_Path%
	gosub Default_Compiler
return

; 选择脚本编辑器
Choose_Editor:
	Gui +OwnDialogs
	FileSelectFile, Editor_Path, 3, , 选择脚本编辑器, 程序(*.exe)
	if Editor_Path<>
		GuiControl,,Editor_Path, %Editor_Path%
return

; 默认脚本编辑器
Default_Editor:
	IfExist, %A_ScriptDir%SciTESciTE.exe
		Editor_Path=%A_ScriptDir%SciTESciTE.exe
	else ifExist, %A_WinDir%system32notepad.exe
			Editor_Path=%A_WinDir%system32notepad.exe
	GuiControl,, Editor_Path, %Editor_Path%
return

; 选择脚本编译器
Choose_Compiler:
	Gui +OwnDialogs
	FileSelectFile, Compiler_Path, 3, , 选择脚本编译器, 程序(*.exe)
	if Compiler_Path<>
		GuiControl,,Compiler_Path, %Compiler_Path%
return

; 默认脚本编译器
Default_Compiler:
	GuiControlGet, AHK_Path
	SplitPath, AHK_Path, ,AHK_Dir
	IfExist, %AHK_Dir%CompilerAhk2Exe.exe
	{
		Compiler_Path=%AHK_Dir%CompilerAhk2Exe.exe
		GuiControl,, Compiler_Path, %Compiler_Path%
	}
return

; 设置
Install:
	Gui, Submit
	IfNotExist, %AHK_Path%
	{
		MsgBox, 16, ScriptSetting %Script_Version%, AutoHotkey 路径错误 !
		return
	}

	IfNotExist, %Editor_Path%
	{
		MsgBox, 16, ScriptSetting %Script_Version%, 编辑器路径错误 !
		return
	}

	IfNotExist, %Compiler_Path%
	{
		MsgBox, 16, ScriptSetting %Script_Version%, 编译器路径错误 !
		return
	}

	; 写入注册表
	RegWrite, REG_SZ, %RootKey%, %Subkey%.ahk,, %FileType%
	if New_Script=1
	{
		RegWrite, REG_SZ, %RootKey%, %Subkey%.ahkShellNew, FileName, %Template_Name%
		IfNotExist, %A_WinDir%ShellNew%Template_Name%
			gosub Create_Template
	}
	else
	{
		; --- 20190207 晓亮修改 ---
		; --- 此处不要删除右键新建ahk文件的菜单所以注释掉此代码
		;RegDelete, %RootKey%, %Subkey%.ahkShellNew
		IfExist, %A_WinDir%ShellNew%Template_Name%
			gosub Delete_Template
	}

	RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%,, AutoHotkey 脚本
	RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%DefaultIcon,, %AHK_Path%`,1
	RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%Shell,, Open
	RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%ShellOpen,, 运行脚本
	RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%ShellOpenCommand,, "%AHK_Path%" "`%1" `%*
	RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%ShellEdit,, 编辑脚本
	RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%ShellEditCommand,, "%Editor_Path%" "`%1"
	RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%ShellCompile,, 编译脚本
	IfInString, Compiler_Path, Ahk2Exe.exe
		RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%ShellCompileCommand,, "%Compiler_Path%" /in "`%1"
	else
		RegWrite, REG_SZ, %RootKey%, %Subkey%%FileType%ShellCompileCommand,, "%Compiler_Path%" "`%1"

/*		新版的scite不需要将“SciTEUser.properties”放在“USERPROFILE”目录下了
if Editor_Path=%A_ScriptDir%SciTESciTE.exe
{
EnvGet,USERPROFILE,USERPROFILE
FileCopy,%A_ScriptDir%SciTESciTEUser.properties,%USERPROFILE%SciTEUser.properties,1
}
*/

	;MsgBox, 64, ScriptSetting %Script_Version%, 设置完毕 !
	ExitApp

	; 卸载
Uninstall:
	; --- 20190207 晓亮修改 ---
	;MsgBox, 36, ScriptSetting %Script_Version%
	;, 注意:卸载后您将无法通过双击来运行脚本,也不能通过右键菜单来启动脚本编辑器...`n`n确定要取消 AHK 脚本的系统关联吗 ?
	;IfMsgBox, Yes
	;{
	;RegDelete, %RootKey%, %Subkey%.ahk
	;RegDelete, %RootKey%, %Subkey%%FileType%
	;gosub Delete_Template
	;ExitApp
	;}
return

; 编辑脚本模板
Edit_Template:
	GuiControlGet, Editor_Path
	IfNotExist, %Editor_Path%
	{
		MsgBox, 64, ScriptSetting %Script_Version%, 脚本编辑器路径错误 !
		return
	}
	IfNotExist, %A_WinDir%ShellNew%Template_Name%
		gosub Create_Template
	Run, %Editor_Path% %A_WinDir%ShellNew%Template_Name%
return

; 使编辑脚本模板按钮有效/无效
New_Script:
	GuiControlGet, New_Script
	if New_Script=0
		GuiControl, Disable, Edit_Template
	else
		GuiControl, Enable, Edit_Template
return

; 新建脚本模板
Create_Template:
	GuiControlGet, AHK_Path
	FileGetVersion, AHK_Ver, %AHK_Path%

	FileAppend,
	(
/*
AutoHotkey 版本: %AHK_Ver%
操作系统:    %A_OSVersion%
作者:        %A_UserName%
网站:        http://www.AutoHotkey.com
脚本说明:
脚本版本:   v1.0
*/

#NoEnv
SendMode Input
SetWorkingDir `%A_ScriptDir`%

	), %A_WinDir%ShellNew%Template_Name%

	GuiControl, Enable, Delete_Template ; 使“删除脚本模板”按钮有效
return

; 删除脚本模板
Delete_Template:

	; --- 20190207 晓亮修改 ---
	;MsgBox, 36, ScriptSetting %Script_Version%
	;	, 要删除当前的 AHK 脚本模板吗 ?`n`n脚本模板被删除后,仍可通过本工具重建模板。
	;IfMsgBox, Yes
	;FileDelete, %A_WinDir%ShellNew%Template_Name%
	;GuiControl, Disable, Delete_Template ; 使“删除脚本模板”按钮无效
return

; 打开网站
Website:
	Run, http://hi.baidu.com/jdchenjian
return

; 从注册表值字符串中提取路径
PathGetPath(pSourceCmd)
{
	local Path, ArgsStartPos = 0
	if (SubStr(pSourceCmd, 1, 1) = """")
		Path := SubStr(pSourceCmd, 2, InStr(pSourceCmd, """", False, 2) - 2)
	else
	{
		ArgsStartPos := InStr(pSourceCmd, " ")
		if ArgsStartPos
			Path := SubStr(pSourceCmd, 1, ArgsStartPos - 1)
		else
			Path = %pSourceCmd%
	}
	return Path
}

 

一些常用代码堆在下面,备份,备忘,备查,备用

 

;~  %A_ScriptDir%scripts定时关闭广告窗口.ahk

;~ 定时自动关闭弹出广告窗口
;~ 请使用 AHK管理器AHKManager.ahk 管理和调用此脚本

#SingleInstance,force ;当此脚本已经运行时自动替换旧实例再次运行。
#Persistent  ;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
SetTimer,设置此脚本的运行参数ConfigThisScript,-1000
SetTimer,关广告窗口删除广告文件,3000
return
;
关广告窗口删除广告文件()
{
	DetectHiddenWindows,On
	SetTitleMatchMode,2
	;~ 隐藏迅雷的圆形悬浮小窗口和主窗口
}
设置此脚本的运行参数ConfigThisScript()
{
	;当此脚本已经运行时自动替换旧实例再次运行。
#SingleInstance,force
	;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
#Persistent
	;不检查空变量是否为环境变量(建议所有新脚本使用)。
#NoEnv
	;用强制的方法激活窗口。阻止任务栏按钮的闪烁.
#WinActivateForce
	;不显示托盘图标。
	;~ #NoTrayIcon
	;启用或禁用可能产生错误的特定状况时的警告,例如书写错误或缺少全局声明
	;~ #Warn
	;改变脚本的当前工作目录。
	SetWorkingDir,%A_ScriptDir%
	;设置脚本可以“看见”隐藏的窗口。
	DetectHiddenWindows,On
	;窗口标题匹配模式改成只需某个位置必须包含WinTitle。而不是完全匹配。
	SetTitleMatchMode,2
	;SendInput 通常更快更可靠. 缓存了发送期间任何物理的键盘或鼠标活动, 避免了在发送时夹杂用户的键击.
	SendMode,Input
	;要看源代码语句的解释请自己搜索AutoHotkey的CHM中文帮助文件吧,选中单词后按帮助快捷键 F1
	CoordMode,Mouse,Screen
	CoordMode,Pixel,Screen
	CoordMode,ToolTip,Screen
	ListLines,Off
	SetBatchLines,-1
	SetStoreCapsLockMode, On
	;~ SetBatchLines,
	;~ SetKeyDelay,
	;~ SetWinDelay,
	;~ SetControlDelay,
}
;

;===== 脚本结束 =====

 

;~  %A_ScriptDir%scripts定时关闭广告窗口.ahk

;~ 定时自动关闭弹出广告窗口
;~ 请使用 AHK管理器AHKManager.ahk 管理和调用此脚本

#SingleInstance,force ;当此脚本已经运行时自动替换旧实例再次运行。
#Persistent  ;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
SetTimer,设置此脚本的运行参数ConfigThisScript,-1000
SetTimer,关广告窗口删除广告文件,3000
return
;
关广告窗口删除广告文件()
{
	DetectHiddenWindows,On
	SetTitleMatchMode,2
	FileDelete,D:PersonalDesktop网址大全.lnk
	; 请用 AHKInfo 1.3.5 窗口信息查询工具来获取窗口标题和窗口类名

	;~ 无法自动关闭的垃圾广告窗口列表
	;~ 01-搜狗浏览器网页内嵌弹窗广告
	;~ se://settings/?category=recommend

	WinClose, GoodSync Upgrade ahk_class #32770 ahk_exe GoodSync.exe, _GoodSync_
	WinClose,ahk_exe todaysinfo.exe  ;关闭搜狗输入法的弹窗垃圾广告
	WinClose, 360每日趣玩 ahk_exe 360DayPop.exe,
	WinClose,ahk_exe 360NewsPop.exe
	WinClose, 同花顺机器人 ahk_class 核新同花顺智能机器人,
	WinClose, ahk_class Q360RemindSClass,
	WinClose, ahk_class MsgSrvPushTipClass ahk_exe MultiTip.exe,
	WinClose, 360每日趣玩 ahk_exe 360DayPop.exe,
	WinClose,ahk_exe DesktopRest.exe,
	WinClose, 到期抄报税提示 ahk_class WindowsForms10.Window.8.app.0.1ed9395_r14_ad1 ahk_exe Aisino.Framework.Startup.exe,
	WinClose, 调查问卷 ahk_class WindowsForms10.Window.8.app.0.1ed9395_r14_ad1 ahk_exe Aisino.Framework.Startup.exe,
	WinClose, SysMessageBox ahk_class WindowsForms10.Window.8.app.0.1ed9395_r14_ad1 ahk_exe Aisino.Framework.Startup.exe, 提示
	WinClose, 程序更新 ahk_class TfrmCheckNewVersion ahk_exe USBSafelyRemove.exe, 了解更多...
	WinClose, 小火箭通用加速 ahk_class TXGuiFoundation ahk_exe QQPCRealTimeSpeedup.exe,
	WinClose,ahk_exe dep360.exe,
	WinClose, 360每日趣玩
	WinClose, ahk_exe 360DayPop.exe,
	WinClose, 小浣熊资讯 ahk_class ATL:10150DF0 ahk_exe RaconWifimini.exe, UIActiveX
	WinClose, 年末大促,错过再等一年 ahk_class SDL_app ahk_exe sunloginclient.exe,
	WinClose, ahk_class TitleWnd ahk_exe SGNews.exe,
	WinClose,ahk_exe SGNews.exe,
	WinClose,USB KEY PIN ahk_class #32770 ahk_exe Aisino.Framework.Startup.exe, 请输入KEY的PIN
	WinClose, FF新推荐
	WinClose,热点资讯
	WinClose,ahk_class Q360RemindSClass ahk_exe 360Speedld.exe,
	WinClose, ahk_class SGPopBubbleWindow ahk_exe SGTool.exe,
	WinClose, 今日推荐
	;~ WinClose,向日葵远程控制
}
设置此脚本的运行参数ConfigThisScript()
{
	;当此脚本已经运行时自动替换旧实例再次运行。
#SingleInstance,force
	;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
#Persistent
	;不检查空变量是否为环境变量(建议所有新脚本使用)。
#NoEnv
	;用强制的方法激活窗口。阻止任务栏按钮的闪烁.
#WinActivateForce
	;不显示托盘图标。
	;~ #NoTrayIcon
	;启用或禁用可能产生错误的特定状况时的警告,例如书写错误或缺少全局声明
	;~ #Warn
	;改变脚本的当前工作目录。
	SetWorkingDir,%A_ScriptDir%
	;设置脚本可以“看见”隐藏的窗口。
	DetectHiddenWindows,On
	;窗口标题匹配模式改成只需某个位置必须包含WinTitle。而不是完全匹配。
	SetTitleMatchMode,2
	;SendInput 通常更快更可靠. 缓存了发送期间任何物理的键盘或鼠标活动, 避免了在发送时夹杂用户的键击.
	SendMode,Input
	;要看源代码语句的解释请自己搜索AutoHotkey的CHM中文帮助文件吧,选中单词后按帮助快捷键 F1
	CoordMode,Mouse,Screen
	CoordMode,Pixel,Screen
	CoordMode,ToolTip,Screen
	ListLines,Off
	SetBatchLines,-1
	SetStoreCapsLockMode, On
	;~ SetBatchLines,
	;~ SetKeyDelay,
	;~ SetWinDelay,
	;~ SetControlDelay,
}
;

;===== 脚本结束 =====

 

; 按快捷键`(即波浪号~所在的键盘按键)立即打开随身U盘中的办公专用文件夹
; WorkFolderHotkey.ahk
;
; http://www.autoahk.com/
; https://www.cnblogs.com/delphixx/p/12129024.html
; http://autohotkey.bokee.com/507525091.html

;~ global RetryCount

Hotkey,``,临时热键
;~ :*:/wk::
;~ 临时热键()
return
;
;~ 电影下载快捷键
临时热键()
{
MouseClick, left,  235,  26
Sleep, 200
MouseClick, left,  142,  30
Sleep, 600
MouseClick, left,  98,  483
Sleep, 1200
MouseClick, left,  142,  30
Sleep, 200
MouseClick, left,  80,  79
Sleep, 200
MouseMove,  695,  508
}

;
;~ 下载电影快捷键
;~ 临时热键()
;~ {
;~ MouseClick, left,  235,  26
;~ Sleep, 200
;~ MouseClick, left,  142,  30
;~ Sleep, 200
;~ MouseClick, left,  98,  483
;~ Sleep, 800
;~ MouseClick, left,  142,  30
;~ Sleep, 200
;~ MouseClick, left,  80,  79
;~ Sleep, 200
;~ MouseMove,  695,  508
;~ }

;
;~ 临时热键()
;~ {
	;~ ; ===== 临时热键 =====
	;~ RetryCount =0

	;~ 文字=

	;~ 文字.="|<>48.c3U100vfaPzTyzUBqP00yzvjyPDQyz000300yDvjqPzTy705qOU1ylVVqMbRyxUHqQU1yzsKXzbRyzkW80U1yz0MU"

	;~ Send,{Down 9}

;~ Sleep,500
	;~ 文字=

	;~ 文字.="|<>25.0E0Cvzrw03vzitxy00yDvjz3U0TgMPjrg07vzavxzU1yz1"

	;~ if 查找文字(709,522,150000,150000,文字,"*187",X,Y,OCR,0,0)
	;~ {
		;~ CoordMode, Mouse
		;~ MouseMove, X, Y

		;~ Click
		;~ ;等待指定标题窗口出现
		;~ WinWait, 搜狗高速下载 ahk_exe SogouExplorer.exe,

		;~ ;点击窗口内指定坐标
		ControlClick, x366 y164, 搜狗高速下载 ahk_class SE_SelectDlPath ahk_exe SogouExplorer.exe,
		;~ Send,{Enter}
		;~ Sleep,500
		;~ ;等待指定标题窗口出现
		;~ WinActivate,搜狗高速浏览器 ahk_class SE_SogouExplorerFrame ahk_exe SogouExplorer.exe,
		;~ Sleep,500
		;~ Send,{CtrlDown}w{CtrlUp}
	;~ }




	;~ ; ===== 临时热键 =====
;~ }
;~ ;
;~ ;---- 将后面的函数附加到自己的脚本中 ----
;~ ;-----------------------------------------
;~ ; 查找屏幕文字/图像字库及OCR识别
;~ ; 注意:参数中的x、y为中心点坐标,w、h为左右上下偏移
;~ ; cha1、cha0分别为0、_字符的容许减少百分比
;~ ;-----------------------------------------
;~ 查找文字(x,y,w,h,wz,c,ByRef rx="",ByRef ry="",ByRef ocr=""
	;~ , cha1=0, cha0=0)
;~ {
	;~ xywh2xywh(x-w,y-h,2*w+1,2*h+1,x,y,w,h)
	;~ if (w<1 or h<1)
		;~ return, 0
	;~ bch:=A_BatchLines
	;~ SetBatchLines, -1
	;~ ;--------------------------------------
	;~ GetBitsFromScreen(x,y,w,h,Scan0,Stride,bits)
	;~ ;--------------------------------------
	;~ ; 设定图内查找范围,注意不要越界
	;~ sx:=0, sy:=0, sw:=w, sh:=h
	;~ if PicOCR(Scan0,Stride,sx,sy,sw,sh,wz,c
		;~ ,rx,ry,ocr,cha1,cha0)
	;~ {
		;~ rx+=x, ry+=y
		;~ SetBatchLines, %bch%
		;~ return, 1
	;~ }
	;~ ; 容差为0的若失败则使用 5% 的容差再找一次
	;~ if (cha1=0 and cha0=0)
		;~ and PicOCR(Scan0,Stride,sx,sy,sw,sh,wz,c
		;~ ,rx,ry,ocr,0.05,0.05)
	;~ {
		;~ rx+=x, ry+=y
		;~ SetBatchLines, %bch%
		;~ return, 1
	;~ }
	;~ SetBatchLines, %bch%
	;~ return, 0
;~ }

;~ ;-- 规范输入范围在屏幕范围内
;~ xywh2xywh(x1,y1,w1,h1,ByRef x,ByRef y,ByRef w,ByRef h)
;~ {
	;~ ; 获取包含所有显示器的虚拟屏幕范围
	;~ SysGet, zx, 76
	;~ SysGet, zy, 77
	;~ SysGet, zw, 78
	;~ SysGet, zh, 79
	;~ left:=x1, Right:=x1+w1-1, up:=y1, down:=y1+h1-1
	;~ left:=left<zx ? zx:left, Right:=Right>zx+zw-1 ? zx+zw-1:Right
	;~ up:=up<zy ? zy:up, down:=down>zy+zh-1 ? zy+zh-1:down
	;~ x:=left, y:=up, w:=Right-left+1, h:=down-up+1
;~ }

;~ ;-- 获取屏幕图像的内存数据,图像包括透明窗口
;~ GetBitsFromScreen(x,y,w,h,ByRef Scan0,ByRef Stride,ByRef bits)
;~ {
	;~ VarSetCapacity(bits, w*h*4, 0)
	;~ Ptr:=A_PtrSize ? "Ptr" : "UInt"
	;~ ; 桌面窗口对应包含所有显示器的虚拟屏幕
	;~ win:=DllCall("GetDesktopWindow", Ptr)
	;~ hDC:=DllCall("GetWindowDC", Ptr,win, Ptr)
	;~ mDC:=DllCall("CreateCompatibleDC", Ptr,hDC, Ptr)
	;~ hBM:=DllCall("CreateCompatibleBitmap", Ptr,hDC
		;~ , "int",w, "int",h, Ptr)
	;~ oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,hBM, Ptr)
	;~ DllCall("BitBlt", Ptr,mDC, "int",0, "int",0, "int",w, "int",h
		;~ , Ptr,hDC, "int",x, "int",y, "uint",0x00CC0020|0x40000000)
	;~ ;--------------------------
	;~ VarSetCapacity(bi, 40, 0)
	;~ NumPut(40, bi, 0, "int"), NumPut(w, bi, 4, "int")
	;~ NumPut(-h, bi, 8, "int"), NumPut(1, bi, 12, "short")
	;~ NumPut(bpp:=32, bi, 14, "short"), NumPut(0, bi, 16, "int")
	;~ ;--------------------------
	;~ DllCall("GetDIBits", Ptr,mDC, Ptr,hBM
		;~ , "int",0, "int",h, Ptr,&bits, Ptr,&bi, "int",0)
	;~ DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
	;~ DllCall("DeleteObject", Ptr,hBM)
	;~ DllCall("DeleteDC", Ptr,mDC)
	;~ DllCall("ReleaseDC", Ptr,win, Ptr,hDC)
	;~ Scan0:=&bits, Stride:=((w*bpp+31)//32)*4
;~ }

;~ ;-----------------------------------------
;~ ; 图像内查找文字/图像字符串及OCR函数
;~ ;-----------------------------------------
;~ PicOCR(Scan0, Stride, sx, sy, sw, sh, wenzi, c
	;~ , ByRef rx, ByRef ry, ByRef ocr, cha1, cha0)
;~ {
	;~ static MyFunc
	;~ if !MyFunc
	;~ {
		;~ x32:="5589E55383EC608B45200FAF45188B551CC1E20201D0894"
		;~ . "5F08B5524B80000000029D0C1E00289C28B451801D08945ECC"
		;~ . "745E800000000C745D400000000C745D0000000008B4524894"
		;~ . "5CC8B45288945C8C745C400000000837D08000F85B20000008"
		;~ . "B450CC1E81025FF0000008945C08B450CC1E80825FF0000008"
		;~ . "945BC8B450C25FF0000008945B8C745F400000000EB75C745F"
		;~ . "800000000EB5A8B45F083C00289C28B451401D00FB6000FB6C"
		;~ . "03B45C075368B45F083C00189C28B451401D00FB6000FB6C03"
		;~ . "B45BC751E8B55F08B451401D00FB6000FB6C03B45B8750B8B5"
		;~ . "5E88B453001D0C600318345F8018345F0048345E8018B45F83"
		;~ . "B45247C9E8345F4018B45EC0145F08B45F43B45287C83E9170"
		;~ . "20000837D08010F85A30000008B450C83C001C1E00789450CC"
		;~ . "745F400000000EB7DC745F800000000EB628B45F083C00289C"
		;~ . "28B451401D00FB6000FB6C06BD0268B45F083C00189C18B451"
		;~ . "401C80FB6000FB6C06BC04B8D0C028B55F08B451401D00FB60"
		;~ . "00FB6D089D0C1E00429D001C83B450C730B8B55E88B453001D"
		;~ . "0C600318345F8018345F0048345E8018B45F83B45247C96834"
		;~ . "5F4018B45EC0145F08B45F43B45280F8C77FFFFFFE96A01000"
		;~ . "0C745F400000000EB7BC745F800000000EB608B55E88B452C8"
		;~ . "D0C028B45F083C00289C28B451401D00FB6000FB6C06BD0268"
		;~ . "B45F083C00189C38B451401D80FB6000FB6C06BC04B8D1C028"
		;~ . "B55F08B451401D00FB6000FB6D089D0C1E00429D001D8C1F80"
		;~ . "788018345F8018345F0048345E8018B45F83B45247C988345F"
		;~ . "4018B45EC0145F08B45F43B45280F8C79FFFFFF8B452483E80"
		;~ . "18945B48B452883E8018945B0C745F401000000E9B0000000C"
		;~ . "745F801000000E9940000008B45F40FAF452489C28B45F801D"
		;~ . "08945E88B55E88B452C01D00FB6000FB6D08B450C01D08945E"
		;~ . "C8B45E88D50FF8B452C01D00FB6000FB6C03B45EC7F488B45E"
		;~ . "88D50018B452C01D00FB6000FB6C03B45EC7F328B45E82B452"
		;~ . "489C28B452C01D00FB6000FB6C03B45EC7F1A8B55E88B45240"
		;~ . "1D089C28B452C01D00FB6000FB6C03B45EC7E0B8B55E88B453"
		;~ . "001D0C600318345F8018B45F83B45B40F8C60FFFFFF8345F40"
		;~ . "18B45F43B45B00F8C44FFFFFFC745E800000000E9E30000008"
		;~ . "B45E88D1485000000008B454001D08B008945E08B45E08945E"
		;~ . "48B45E48945F08B45E883C0018D1485000000008B454001D08"
		;~ . "B008945B48B45E883C0028D1485000000008B454001D08B008"
		;~ . "945B0C745F400000000EB7CC745F800000000EB678B45F08D5"
		;~ . "0018955F089C28B453401D00FB6003C3175278B45E48D50018"
		;~ . "955E48D1485000000008B453801C28B45F40FAF452489C18B4"
		;~ . "5F801C88902EB258B45E08D50018955E08D1485000000008B4"
		;~ . "53C01C28B45F40FAF452489C18B45F801C889028345F8018B4"
		;~ . "5F83B45B47C918345F4018B45F43B45B00F8C78FFFFFF8345E"
		;~ . "8078B45E83B45440F8C11FFFFFF8B45D00FAF452489C28B45D"
		;~ . "401D08945F08B45240FAF45C8BA0100000029C289D08945E4C"
		;~ . "745F800000000E9B5020000C745F400000000E993020000C74"
		;~ . "5E800000000E9710200008B45E883C0018D1485000000008B4"
		;~ . "54001D08B008945B48B45E883C0028D1485000000008B45400"
		;~ . "1D08B008945B08B55F88B45B401D03B45CC0F8F2D0200008B5"
		;~ . "5F48B45B001D03B45C80F8F1C0200008B45E88D14850000000"
		;~ . "08B454001D08B008945E08B45E883C0038D1485000000008B4"
		;~ . "54001D08B008945AC8B45E883C0048D1485000000008B45400"
		;~ . "1D08B008945A88B45E883C0058D1485000000008B454001D08"
		;~ . "B008945DC8B45E883C0068D1485000000008B454001D08B008"
		;~ . "945D88B45AC3945A80F4D45A88945A4C745EC00000000E9820"
		;~ . "000008B45EC3B45AC7D378B55E08B45EC01D08D14850000000"
		;~ . "08B453801D08B108B45F001D089C28B453001D00FB6003C317"
		;~ . "40E836DDC01837DDC000F884E0100008B45EC3B45A87D378B5"
		;~ . "5E08B45EC01D08D1485000000008B453C01D08B108B45F001D"
		;~ . "089C28B453001D00FB6003C30740E836DD801837DD8000F881"
		;~ . "20100008345EC018B45EC3B45A40F8C72FFFFFF837DC4000F8"
		;~ . "5840000008B551C8B45F801C28B454889108B454883C0048B4"
		;~ . "D208B55F401CA89108B45488D50088B45B489028B45488D500"
		;~ . "C8B45B08902C745C4040000008B45F42B45B08945D08B55B08"
		;~ . "9D001C001D08945C88B55B089D0C1E00201D001C083C064894"
		;~ . "5CC837DD0007907C745D0000000008B45282B45D03B45C87D2"
		;~ . "E8B45282B45D08945C8EB238B45F83B45107E1B8B45C48D500"
		;~ . "18955C48D1485000000008B454801D0C700FFFFFFFF8B45C48"
		;~ . "D50018955C48D1485000000008B454801D08B55E883C207891"
		;~ . "0817DC4FD0300007F788B55F88B45B401D00145D48B45242B4"
		;~ . "5D43B45CC0F8D60FDFFFF8B45242B45D48945CCE952FDFFFF9"
		;~ . "0EB0490EB01908345E8078B45E83B45440F8C83FDFFFF8345F"
		;~ . "4018B45240145F08B45F43B45C80F8C61FDFFFF8345F8018B4"
		;~ . "5E40145F08B45F83B45CC0F8C3FFDFFFF837DC4007508B8000"
		;~ . "00000EB1B908B45C48D1485000000008B454801D0C70000000"
		;~ . "000B80100000083C4605B5DC2440090"
		;~ x64:="554889E54883EC60894D10895518448945204C894D288B4"
		;~ . "5400FAF45308B5538C1E20201D08945F48B5548B8000000002"
		;~ . "9D0C1E00289C28B453001D08945F0C745EC00000000C745D80"
		;~ . "0000000C745D4000000008B45488945D08B45508945CCC745C"
		;~ . "800000000837D10000F85C90000008B4518C1E81025FF00000"
		;~ . "08945C48B4518C1E80825FF0000008945C08B451825FF00000"
		;~ . "08945BCC745F800000000E985000000C745FC00000000EB6A8"
		;~ . "B45F483C0024863D0488B45284801D00FB6000FB6C03B45C47"
		;~ . "5438B45F483C0014863D0488B45284801D00FB6000FB6C03B4"
		;~ . "5C075288B45F44863D0488B45284801D00FB6000FB6C03B45B"
		;~ . "C75108B45EC4863D0488B45604801D0C600318345FC018345F"
		;~ . "4048345EC018B45FC3B45487C8E8345F8018B45F00145F48B4"
		;~ . "5F83B45500F8C6FFFFFFFE959020000837D10010F85B600000"
		;~ . "08B451883C001C1E007894518C745F800000000E98D000000C"
		;~ . "745FC00000000EB728B45F483C0024863D0488B45284801D00"
		;~ . "FB6000FB6C06BD0268B45F483C0014863C8488B45284801C80"
		;~ . "FB6000FB6C06BC04B8D0C028B45F44863D0488B45284801D00"
		;~ . "FB6000FB6D089D0C1E00429D001C83B451873108B45EC4863D"
		;~ . "0488B45604801D0C600318345FC018345F4048345EC018B45F"
		;~ . "C3B45487C868345F8018B45F00145F48B45F83B45500F8C67F"
		;~ . "FFFFFE999010000C745F800000000E98D000000C745FC00000"
		;~ . "000EB728B45EC4863D0488B4558488D0C028B45F483C002486"
		;~ . "3D0488B45284801D00FB6000FB6C06BD0268B45F483C0014C6"
		;~ . "3C0488B45284C01C00FB6000FB6C06BC04B448D04028B45F44"
		;~ . "863D0488B45284801D00FB6000FB6D089D0C1E00429D04401C"
		;~ . "0C1F80788018345FC018345F4048345EC018B45FC3B45487C8"
		;~ . "68345F8018B45F00145F48B45F83B45500F8C67FFFFFF8B454"
		;~ . "883E8018945B88B455083E8018945B4C745F801000000E9CA0"
		;~ . "00000C745FC01000000E9AE0000008B45F80FAF454889C28B4"
		;~ . "5FC01D08945EC8B45EC4863D0488B45584801D00FB6000FB6D"
		;~ . "08B451801D08945F08B45EC4898488D50FF488B45584801D00"
		;~ . "FB6000FB6C03B45F07F538B45EC4898488D5001488B4558480"
		;~ . "1D00FB6000FB6C03B45F07F388B45EC2B45484863D0488B455"
		;~ . "84801D00FB6000FB6C03B45F07F1D8B55EC8B454801D04863D"
		;~ . "0488B45584801D00FB6000FB6C03B45F07E108B45EC4863D04"
		;~ . "88B45604801D0C600318345FC018B45FC3B45B80F8C46FFFFF"
		;~ . "F8345F8018B45F83B45B40F8C2AFFFFFFC745EC00000000E90"
		;~ . "D0100008B45EC4898488D148500000000488B8580000000480"
		;~ . "1D08B008945E48B45E48945E88B45E88945F48B45EC4898488"
		;~ . "3C001488D148500000000488B85800000004801D08B008945B"
		;~ . "88B45EC48984883C002488D148500000000488B85800000004"
		;~ . "801D08B008945B4C745F800000000E989000000C745FC00000"
		;~ . "000EB748B45F48D50018955F44863D0488B45684801D00FB60"
		;~ . "03C31752C8B45E88D50018955E84898488D148500000000488"
		;~ . "B45704801C28B45F80FAF454889C18B45FC01C88902EB2A8B4"
		;~ . "5E48D50018955E44898488D148500000000488B45784801C28"
		;~ . "B45F80FAF454889C18B45FC01C889028345FC018B45FC3B45B"
		;~ . "87C848345F8018B45F83B45B40F8C6BFFFFFF8345EC078B45E"
		;~ . "C3B85880000000F8CE4FEFFFF8B45D40FAF454889C28B45D80"
		;~ . "1D08945F48B45480FAF45CCBA0100000029C289D08945E8C74"
		;~ . "5FC00000000E929030000C745F800000000E907030000C745E"
		;~ . "C00000000E9E20200008B45EC48984883C001488D148500000"
		;~ . "000488B85800000004801D08B008945B88B45EC48984883C00"
		;~ . "2488D148500000000488B85800000004801D08B008945B48B5"
		;~ . "5FC8B45B801D03B45D00F8F8C0200008B55F88B45B401D03B4"
		;~ . "5CC0F8F7B0200008B45EC4898488D148500000000488B85800"
		;~ . "000004801D08B008945E48B45EC48984883C003488D1485000"
		;~ . "00000488B85800000004801D08B008945B08B45EC48984883C"
		;~ . "004488D148500000000488B85800000004801D08B008945AC8"
		;~ . "B45EC48984883C005488D148500000000488B8580000000480"
		;~ . "1D08B008945E08B45EC48984883C006488D148500000000488"
		;~ . "B85800000004801D08B008945DC8B45B03945AC0F4D45AC894"
		;~ . "5A8C745F000000000E9920000008B45F03B45B07D3F8B55E48"
		;~ . "B45F001D04898488D148500000000488B45704801D08B108B4"
		;~ . "5F401D04863D0488B45604801D00FB6003C31740E836DE0018"
		;~ . "37DE0000F88790100008B45F03B45AC7D3F8B55E48B45F001D"
		;~ . "04898488D148500000000488B45784801D08B108B45F401D04"
		;~ . "863D0488B45604801D00FB6003C30740E836DDC01837DDC000"
		;~ . "F88350100008345F0018B45F03B45A80F8C62FFFFFF837DC80"
		;~ . "00F85970000008B55388B45FC01C2488B85900000008910488"
		;~ . "B85900000004883C0048B4D408B55F801CA8910488B8590000"
		;~ . "000488D50088B45B88902488B8590000000488D500C8B45B48"
		;~ . "902C745C8040000008B45F82B45B48945D48B55B489D001C00"
		;~ . "1D08945CC8B55B489D0C1E00201D001C083C0648945D0837DD"
		;~ . "4007907C745D4000000008B45502B45D43B45CC7D368B45502"
		;~ . "B45D48945CCEB2B8B45FC3B45207E238B45C88D50018955C84"
		;~ . "898488D148500000000488B85900000004801D0C700FFFFFFF"
		;~ . "F8B45C88D50018955C84898488D148500000000488B8590000"
		;~ . "0004801D08B55EC83C2078910817DC8FD0300007F7B8B55FC8"
		;~ . "B45B801D00145D88B45482B45D83B45D00F8DEFFCFFFF8B454"
		;~ . "82B45D88945D0E9E1FCFFFF90EB0490EB01908345EC078B45E"
		;~ . "C3B85880000000F8C0FFDFFFF8345F8018B45480145F48B45F"
		;~ . "83B45CC0F8CEDFCFFFF8345FC018B45E80145F48B45FC3B45D"
		;~ . "00F8CCBFCFFFF837DC8007508B800000000EB23908B45C8489"
		;~ . "8488D148500000000488B85900000004801D0C70000000000B"
		;~ . "8010000004883C4605DC390909090909090909090"
		;~ MCode(MyFunc, A_PtrSize=8 ? x64:x32)
	;~ }
	;~ ;--------------------------------------
	;~ ; 统计字库文字的个数和宽高,将解释文字存入数组并删除<>
	;~ ;--------------------------------------
	;~ wenzitab:=[], num:=0, wz:="", j:=""
	;~ loop, Parse, wenzi, |
	;~ {
		;~ v:=A_LoopField, txt:="", e1:=cha1, e0:=cha0
		;~ ; 用角括号输入每个字库字符串的识别结果文字
		;~ if RegExMatch(v,"<([^>]*)>",r)
			;~ v:=StrReplace(v,r), txt:=r1
		;~ ; 可以用中括号输入每个文字的两个容差,以逗号分隔
		;~ if RegExMatch(v,"[([^]]*)]",r)
		;~ {
			;~ v:=StrReplace(v,r), r2:=""
			;~ StringSplit, r, r1, `,
			;~ e1:=r1, e0:=r2
		;~ }
		;~ ; 记录每个文字的起始位置、宽、高、10字符的数量和容差
		;~ StringSplit, r, v, .
		;~ w:=r1, v:=base64tobit(r2), h:=StrLen(v)//w
		;~ if (r0<2 or w>sw or h>sh or StrLen(v)!=w*h)
			;~ continue
		;~ if InStr(c,"-")
		;~ {
			;~ r:=e1, e1:=e0, e0:=r, v:=StrReplace(v,"1","_")
			;~ v:=StrReplace(StrReplace(v,"0","1"),"_","0")
		;~ }
		;~ len1:=StrLen(StrReplace(v,"0"))
		;~ len0:=StrLen(StrReplace(v,"1"))
		;~ e1:=Round(len1*e1), e0:=Round(len0*e0)
		;~ j.=StrLen(wz) "|" w "|" h
		;~ . "|" len1 "|" len0 "|" e1 "|" e0 "|"
		;~ wz.=v, wenzitab[++num]:=Trim(txt)
	;~ }
	;~ IfEqual, wz,, return, 0
	;~ ;--------------------------------------
	;~ ; wz 使用Astr参数类型可以自动转为ANSI版字符串
	;~ ; in 输入各文字的起始位置等信息,out 返回结果
	;~ ; ss 等为临时内存,jiange 超过间隔就会加入*号
	;~ ;--------------------------------------
	;~ mode:=InStr(c,"**") ? 2 : InStr(c,"*") ? 1 : 0
	;~ c:=RegExReplace(c,"[*-]"), jiange:=5, num*=7
	;~ VarSetCapacity(in,num*4,0), i:=-4
	;~ loop, Parse, j, |
		;~ if (A_Index<=num)
			;~ NumPut(A_LoopField, in, i+=4, "int")
	;~ VarSetCapacity(gs, sw*sh)
	;~ VarSetCapacity(ss, sw*sh, Asc("0"))
	;~ k:=StrLen(wz)*4
	;~ VarSetCapacity(s1, k, 0), VarSetCapacity(s0, k, 0)
	;~ VarSetCapacity(out, 1024*4, 0)
	;~ if DllCall(&MyFunc, "int",mode, "uint",c
		;~ , "int",jiange, "ptr",Scan0, "int",Stride
		;~ , "int",sx, "int",sy, "int",sw, "int",sh
		;~ , "ptr",&gs, "ptr",&ss
		;~ , "Astr",wz, "ptr",&s1, "ptr",&s0
		;~ , "ptr",&in, "int",num, "ptr",&out)
	;~ {
		;~ ocr:="", i:=-4 ; 返回第一个文字的中心位置
		;~ x:=NumGet(out,i+=4,"int"), y:=NumGet(out,i+=4,"int")
		;~ w:=NumGet(out,i+=4,"int"), h:=NumGet(out,i+=4,"int")
		;~ rx:=x+w//2, ry:=y+h//2
		;~ while (k:=NumGet(out,i+=4,"int"))
			;~ v:=wenzitab[k//7], ocr.=v="" ? "*" : v
		;~ return, 1
	;~ }
	;~ return, 0
;~ }

;~ MCode(ByRef code, hex)
;~ {
	;~ ListLines, Off
	;~ bch:=A_BatchLines
	;~ SetBatchLines, -1
	;~ VarSetCapacity(code, StrLen(hex)//2)
	;~ loop, % StrLen(hex)//2
		;~ NumPut("0x" . SubStr(hex,2*A_Index-1,2)
		;~ , code, A_Index-1, "char")
	;~ Ptr:=A_PtrSize ? "Ptr" : "UInt"
	;~ DllCall("VirtualProtect", Ptr,&code, Ptr
		;~ ,VarSetCapacity(code), "uint",0x40, Ptr . "*",0)
	;~ SetBatchLines, %bch%
	;~ ListLines, On
;~ }
;~ ;
;~ ;  本文的最后修改日期是  公元2019年11月11日
;~ ;  本文的网址是  https://gitee.com/weiyunwps618/codes
;~ ;  本文的网址是  https://www.cnblogs.com/delphixx
;~ ;  晓亮(weiyunwps618)的腾讯QQ邮箱地址是  595076941@qq.com )
;~ ;  晓亮(weiyunwps618)的中国移动手机号码是  138####5488 )
;~ ; 此AHK脚本的测试环境是  Windows 7 Pro SP1 VL 和 AutoHotkey v1.1.30.01
;~ ;
;~ base64tobit(s) {
	;~ ListLines, Off
	;~ s:=RegExReplace(s,"s+")
	;~ Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	;~ . "abcdefghijklmnopqrstuvwxyz"
	;~ SetFormat, IntegerFast, d
	;~ StringCaseSense, On
	;~ loop, Parse, Chars
	;~ {
		;~ i:=A_Index-1, v:=(i>>5&1) . (i>>4&1)
		;~ . (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
		;~ s:=StrReplace(s,A_LoopField,v)
	;~ }
	;~ StringCaseSense, Off
	;~ s:=SubStr(s,1,InStr(s,"1",0,0)-1)
	;~ ListLines, On
	;~ return, s
;~ }

;~ bit2base64(s) {
	;~ ListLines, Off
	;~ s:=RegExReplace(s,"s+")
	;~ s.=SubStr("100000",1,6-Mod(StrLen(s),6))
	;~ s:=RegExReplace(s,".{6}","|$0")
	;~ Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	;~ . "abcdefghijklmnopqrstuvwxyz"
	;~ SetFormat, IntegerFast, d
	;~ loop, Parse, Chars
	;~ {
		;~ i:=A_Index-1, v:="|" . (i>>5&1) . (i>>4&1)
		;~ . (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
		;~ s:=StrReplace(s,v,A_LoopField)
	;~ }
	;~ ListLines, On
	;~ return, s
;~ }

*/

/************ 机器码的C源码 ************

int __attribute__((__stdcall__)) OCR( int mode
, unsigned int c, int jiange, unsigned char * Bmp
, int Stride, int sx, int sy, int sw, int sh
, unsigned char * gs, char * ss
, char * wz, int * s1, int * s0
, int * in, int num, int * out )
{
int x, y, o=sy*Stride+sx*4, j=Stride-4*sw, i=0;
int o1, o2, w, h, max, len1, len0, e1, e0;
int sx1=0, sy1=0, sw1=sw, sh1=sh, Ptr=0;

//准备工作一:先将图像各点在ss中转化为01字符
if (mode==0) //颜色模式
{
int R=(c>>16)&0xFF, G=(c>>8)&0xFF, B=c&0xFF;
for (y=0; y<sh; y++, o+=j)
for (x=0; x<sw; x++, o+=4, i++)
if (Bmp[2+o]==R && Bmp[1+o]==G && Bmp[o]==B)
ss[i]='1';
}
else if (mode==1) //灰度阀值模式
{
c=(c+1)*128;
for (y=0; y<sh; y++, o+=j)
for (x=0; x<sw; x++, o+=4, i++)
if (Bmp[2+o]*38+Bmp[1+o]*75+Bmp[o]*15<c)
ss[i]='1';
}
else //mode==2,边缘灰差模式
{
for (y=0; y<sh; y++, o+=j)
{
for (x=0; x<sw; x++, o+=4, i++)
gs[i]=(Bmp[2+o]*38+Bmp[1+o]*75+Bmp[o]*15)>>7;
}
w=sw-1; h=sh-1;
for (y=1; y<h; y++)
{
for (x=1; x<w; x++)
{
i=y*sw+x; j=gs[i]+c;
if (gs[i-1]>j || gs[i+1]>j
|| gs[i-sw]>j || gs[i+sw]>j)
ss[i]='1';
}
}
}

//准备工作二:生成s1、s0查表数组
for (i=0; i<num; i+=7)
{
o=o1=o2=in[i]; w=in[i+1]; h=in[i+2];
for (y=0; y<h; y++)
{
for (x=0; x<w; x++)
{
if (wz[o++]=='1')
s1[o1++]=y*sw+x;
else
s0[o2++]=y*sw+x;
}
}
}

//正式工作:ss中每一点都进行一次全字库匹配
NextWenzi:
o=sy1*sw+sx1; o1=1-sw*sh1;
for (x=0; x<sw1; x++, o+=o1)
{
for (y=0; y<sh1; y++, o+=sw)
{
for (i=0; i<num; i+=7)
{
w=in[i+1]; h=in[i+2];
if (x+w>sw1 || y+h>sh1)
continue;
o2=in[i]; len1=in[i+3]; len0=in[i+4];
e1=in[i+5]; e0=in[i+6];
max=len1>len0 ? len1 : len0;
for (j=0; j<max; j++)
{
if (j<len1 && ss[o+s1[o2+j]]!='1' && (--e1)<0)
goto NoMatch;
if (j<len0 && ss[o+s0[o2+j]]!='0' && (--e0)<0)
goto NoMatch;
}
//成功找到文字或图像
if (Ptr==0)
{
out[0]=sx+x; out[1]=sy+y;
out[2]=w; out[3]=h; Ptr=4;
//找到第一个字就确定后续查找的上下范围和右边范围
sy1=y-h; sh1=h*3; sw1=h*10+100;
if (sy1<0)
sy1=0;
if (sh1>sh-sy1)
sh1=sh-sy1;
}
else if (x>jiange) //与前一字间隔较远就添加*号
out[Ptr++]=-1;
out[Ptr++]=i+7;
if (Ptr>1021) //返回的int数组中元素个数不超过1024
goto ReturnOK;
//继续从当前文字右边再次查找
sx1+=x+w;
if (sw1>sw-sx1)
sw1=sw-sx1;
goto NextWenzi;
//------------
NoMatch:
continue;
}
}
}
if (Ptr==0)
return 0;
ReturnOK:
out[Ptr]=0;
return 1;
}

*/
;============ 脚本结束 =================;

 

;~ %A_ScriptDir%scripts设置随系统启动的程序.ahk

#SingleInstance,force ;当此脚本已经运行时自动替换旧实例再次运行。
#Persistent  ;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
#NoEnv  ;不检查空变量是否为环境变量(建议所有新脚本使用)。
#WinActivateForce  ;用强制的方法激活窗口。阻止任务栏按钮的闪烁.
;~ #NoTrayIcon  ;不显示托盘图标。
;~ #Warn
SetWorkingDir,%A_ScriptDir%  ;改变脚本的当前工作目录。
DetectHiddenWindows,On  ;设置脚本可以“看见”隐藏的窗口。
SetTitleMatchMode,2  ;窗口标题匹配模式改成某个位置必须包含WinTitle。

IfExist,% "D:greenRunZRunZ.exe"
{
	Run,"D:greenRunZRunZ.exe"
}



;~ 【管理员】徐晓亮(595076941)  11:34:40
;~ 071-在电脑启动时自动设置WPS2019的定时备份时间间隔为1分钟备份文件保存的位置为D盘-20200809

;~ 【管理员】徐晓亮(595076941)  11:38:37
;~ 备份文件夹删除后WPS2019会自动重新新建文件夹
;~ 这一点非常好

;~ 每次启动电脑是通过导入注册表reg文件自动设置WPS的备份时间间隔为1分钟,备份位置是D:kingsoftoffice6backup

;~ 每次启动都覆盖一下设置,防止丢失设置,丢失文件

;~ 唯一缺点时,有泄密的可能,

;~ 当然也可以启动时调用WinRAR按照日期掩码生成压缩包名称并加密压缩一下备份文件,然后删除WPS备份文件,这样就不容易泄密了
;~ loop,5
;~ {
	;~ FileCopy,"D:greenAHKManagerscriptsregconfig.ini","C:Program FilesOraySunLoginSunloginClient",1
	;~ Process,Close,SunloginClient.exe
;~ }
;~ IfExist,% "C:Program FilesOraySunLoginSunloginClientSunloginClient.exe"
;~ {
	;~ Run,"C:Program FilesOraySunLoginSunloginClientSunloginClient.exe"
;~ }

;;  IfExist,% "D:greenAHKManagerscriptsregAutoBackupWPS.reg"
;;  {
;;  	Run %comspec% /c "regedit /s D:greenAHKManagerscriptsregAutoBackupWPS.reg"
;;  }


;~ IfExist,% "D:greenTrafficMonitor显示网速TrafficMonitor显示网速.exe"
;~ {
	;~ Run,"D:greenTrafficMonitor显示网速TrafficMonitor显示网速.exe"
;~ }

;              IfExist,% "D:greenAHKManagerscriptsdatfavorite3.dat"
;              {
;              	FileCopy,% "D:greenAHKManagerscriptsdatfavorite3.dat",C:UsersAdministratorAppDataRoamingSogouExplorerfavorite3.dat,1
;              }

;~ IfExist,% "D:greenRunZRunZ.ahk"
;~ Run,% "D:greenRunZRunZ.ahk"
;~ IfExist,% "D:greenLaunchyLaunchy.exe"
	;~ Run,% "D:greenLaunchyLaunchy.exe"
;~ SetTimer,WinCloseLaunchy,100
;~ WinCloseLaunchy()
;~ {
;~ WinClose, Launchy ahk_class QTool ahk_exe Launchy.exe
;~ WinCloseTime +=1
;~ if(WinCloseTime>30)
;~ SetTimer,WinCloseLaunchy,Delete
;~ }

IfExist,% "D:greenWiseDesktopWiseDesktop.exe"
	Run,% "D:greenWiseDesktopWiseDesktop.exe"
;~ IfExist,% "C:Program Files (x86)USB Safely RemoveUSBSafelyRemove.exe"
;~ Run,% "C:Program Files (x86)USB Safely RemoveUSBSafelyRemove.exe"
SetTimer,16运行国税金税盘开票软件,-100
return
16运行国税金税盘开票软件()
{
	SetTimer,运行开票软件,-500
	SetTimer,激活登录窗口,500
	SetTimer,单击登录窗口中的确定按钮,500
	SetTimer,关闭上报汇总已成功提示窗口,500
	SetTimer,等待主窗口出现后停止并删除所有Timer定时器,500
}
运行开票软件()
{
	;~ FileCopy,;;;;;D:开票软件913205067037151092.2ConfigCommonConfigBak.xml,D:开票软件913205067037151092.2ConfigCommonConfig.xml,1
	Sleep,500
	IfExist,D:开票软件MainExecute.exe
	{
		Process,Exist,Aisino.Framework.Startup.exe
		if (%ErrorLevel%=0)
		{
			IfWinNotExist,SysMessageBox ahk_class WindowsForms10.Window.8.app.0.2bb23b_r11_ad1 ahk_exe Aisino.Framework.Startup.exe, 提示
			{
				IfWinNotExist,增值税发票税控开票软件
					Run,D:开票软件MainExecute.exe
			}
		}
	}
}
激活登录窗口()
{
	WinGet, WinID, ID,税控发票开票软件
	DllCall("SwitchToThisWindow", "UInt", WinID, "UInt", 1)
}
单击登录窗口中的确定按钮()
{
	ControlClick, WindowsForms10.BUTTON.app.0.1ed9395_r14_ad12, 税控发票开票软件 ahk_class WindowsForms10.Window.8.app.0.1ed9395_r14_ad1, 增值税发票税控开票软
	ControlClick, WindowsForms10.BUTTON.app.0.2bb23b_r11_ad12, 税控发票开票软件 ahk_class WindowsForms10.Window.8.app.0.2bb23b_r11_ad1 ahk_exe Aisino.Framework.Startup.exe, 增值税发票税控开票软
	ControlClick, WindowsForms10.BUTTON.app.0.1ed9395_r12_ad12, 税控发票开票软件 ahk_class WindowsForms10.Window.8.app.0.1ed9395_r12_ad1 ahk_exe Aisino.Framework.Startup.exe, 增值税发票税控开票软
	ControlClick, x658 y322, 汇总信息 ahk_class WindowsForms10.Window.8.app.0.1ed9395_r14_ad1 ahk_exe Aisino.Framework.Startup.exe, 汇总报送已成功!汇总
}
关闭上报汇总已成功提示窗口()
{
	WinClose,SysMessageBox ahk_class WindowsForms10.Window.8.app.0.2bb23b_r11_ad1 ahk_exe Aisino.Framework.Startup.exe, 提示
}
等待主窗口出现后停止并删除所有Timer定时器()
{
	;等待指定标题窗口出现
	IfWinExist, SysMessageBox ahk_exe Aisino.Framework.Startup.exe, 登录错误
		停止并删除所有Timer定时器()

	IfWinExist,增值税发票税控开票软件(金税盘版) V2 ahk_exe Aisino.Framework.Startup.exe
		停止并删除所有Timer定时器()
}

停止并删除所有Timer定时器()
{
	SetTimer,运行开票软件,Delete
	SetTimer,激活登录窗口,Delete
	SetTimer,单击登录窗口中的确定按钮,Delete
	SetTimer,关闭上报汇总已成功提示窗口,Delete
	SetTimer,等待主窗口出现后停止并删除所有Timer定时器,Delete
	;~ MsgBox,开票软件启动成功
	Run,C:WindowsSystem32Rundll32.Exe user32.dll LockWorkStation,,Hide
}
;
ExitApp


;  show = Please Waitting...
;  Gui, Font, S8 Cred Bold, Verdana
;  Gui, Add, Edit, x6 y7 w240 h320 vshow
;  Gui, Show, x131 y91 h337 w255, 批量导入注册表
;  GuiControl,, show, %show%
;  foloder = %A_ScriptDir%reg
;  FileAppend, dir "%foloder%" /b >"%A_ScriptDir%list.txt", %A_ScriptDir%list.cmd
;  run, %A_ScriptDir%list.cmd, , min
;  sleep, 1000
;  GuiControl,, show,
;  Loop
;  {
;  FileReadLine, line, %A_ScriptDir%list.txt, %A_Index%
;  if ErrorLevel = 1
;      break
;  path = %foloder%%line%
;  SplitPath, path, name
;  show = %show%`n注册 %name%
;  GuiControl,, show, %show%
;  FileAppend, regedit /s "%path%"`n, %A_ScriptDir%reg.cmd
;  }
;  run, %A_ScriptDir%reg.cmd, , min
;  FileDelete, %A_ScriptDir%list.txt
;  FileDelete, %A_ScriptDir%list.cmd
;  FileDelete, %A_ScriptDir%reg.cmd
;  ExitApp
;
;  GuiClose:
;  ExitApp

 

;~ %A_ScriptDir%scripts无窗口全局热键定义.ahk
;
; 开机时自动启动的AutoHotkey脚本 2019年10月09日
;
; 计时器创建代码段 -----------------------------------------------------------------------------------------
; SetTimer可以模拟多线程从而不影响主线程的流畅执行
; 请在SciTE4AutoHotkey中选中单词并按快捷键F12跳转到函数定义处
; 绿色免安装程序,统一都分类保存在本地磁盘D分区文件夹 D:green 中
; 例如: MasterSeeker就长期坚持固定不变保存位置在 D:greenMasterSeekerMasterSeeker.exe
; 例如: FileLocator Pro就长期坚持固定不变保存位置在 D:greenFileLocatorFileLocator.exe
; #####################################################################
;
#SingleInstance,force ;当此脚本已经运行时自动替换旧实例再次运行。
#Persistent  ;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。

global ProgramDir
global OpednCount
OpenCount =0
ProgramDir=D:green
SetTimer,01设置全局无窗口快捷键,500
SetTimer,01设置全局无窗口快捷键,300
;  请养成按<Win> + F 隐藏MasterSeeker窗口的习惯
;~ SetTimer,12保持MasterSeeker窗口常驻内存,9000
SetTimer,10设置此脚本的运行参数,-1000
SetTimer,11设置此脚本用户自定义变量,-1000
SetTimer,12防止重复运行此脚本,-1000
return


return
;
; 此脚本相关信息说明段 ---------------------------------------------------------------------------------------
; 用法	               把此AHK脚本文件复制到 “shell:startup”文件夹中
;                          shell:startup”文件夹一般位于开始菜单->所有程序->启动 文件夹
; 作者                  徐晓亮  vlanweiyun618
; 电子邮箱地址     595076941@QQ.com
; 手机号码
;
; 函数子程序定义段 --------------------------------------------------------------------------------------------
;
01设置全局无窗口快捷键()
{
	Sleep,200
	Hotkey,*#n,01激活或隐藏用EmEditor打开的log纯文本编辑窗口  ;  按热键F9手动记录电脑操作日志
	;~ Hotkey,F9,01激活或隐藏用EmEditor打开的log纯文本编辑窗口  ;  按热键F9手动记录电脑操作日志
	;~ Hotkey,``,01激活用WebDrive2019软件连接群晖的WebDAV共享文件夹窗口  ;  按热键`(即左上角的波浪号~)
	Sleep,200
	;~ Hotkey,ScrollLock,关闭显示器屏幕
	Hotkey,ScrollLock,立即锁定电脑桌面
	Sleep,200
	;~ Hotkey,*#n,02激活或隐藏窗口EmEditor
	Sleep,200
	;~ 热键 {Win}+f 总是要被操作系统抢去,所以改成 {Win}+g
	;~ Hotkey,*#g,03激活或隐藏窗口Everything
	Hotkey,*#g,03激活或隐藏窗口MasterSeeker
	Sleep,200
	Hotkey,*#b,04激活或隐藏窗口SogouExplorer
	Sleep,200
	;~ Hotkey,`#t,05激活或隐藏窗口TotalCommander  ;  按热键 Win+E 激活 TotalCommander
	Hotkey,F8,05激活或隐藏窗口TotalCommander  ;  按热键 Win+E 激活 TotalCommander
	Sleep,200
	Hotkey,*#c,06激活或隐藏窗口计算器Calc  ;  按热键 Win + C,打开计算器
	Sleep,200
	Hotkey,*^!E,07用SciTE4AutoHotkey编辑此脚本
	Sleep,200
	Hotkey,*^!R,08重启此脚本
	Sleep,200
	Hotkey,*^F12,09终止此脚本执行  ;按Ctrl+Alt+F10键此脚本立即停止执行并退出
}
;
立即锁定电脑桌面()
{
Run,C:WindowsSystem32Rundll32.Exe user32.dll LockWorkStation,,Hide
Run,C:WindowsSystem32Rundll32.Exe user32.dll LockWorkStation,,Hide
}
;
关闭显示器屏幕()
{
	SendMessage, 0x112, 0xF170, 2,, Program Manager
}
;
01激活或隐藏用EmEditor打开的log纯文本编辑窗口()
{
	FileCreateDir,D:电脑操作日志记录
	mylogtext :=%  "D:电脑操作日志记录电脑操作日志记录" . A_YYYY  . "年" . A_MM . "月" . A_DD  . "日.txt"
	Run,D:greenEmEditorEmEditor.exe %mylogtext%
}
;
01激活用WebDrive2019软件连接群晖的WebDAV共享文件夹窗口()
{
	ToolTip,正在激活WebDrive2019软件连接群晖的WebDAV共享文件夹窗口
	SetTimer,判断WebDrive2019软件是否已经安装,500
	SetTimer,运行WebDrive2019软件,500
	SetTimer,激活WebDrive2019软件窗口,500
	SetTimer,激活并移动单位办公文件夹窗口,500
}
;
判断WebDrive2019软件是否已经安装()
{
	IfNotExist,C:Program FilesWebDriveWebDrive.exe
	{
		ToolTip
		MsgBox,请安装WebDrive
		SetTimer,判断WebDrive2019软件是否已经安装,Delete
		SetTimer,运行WebDrive2019软件,Delete
		SetTimer,激活WebDrive2019软件窗口,Delete
		SetTimer,激活并移动单位办公文件夹窗口,Delete
	}
	else
	{
		SetTimer,判断WebDrive2019软件是否已经安装,Delete
	}
}
;
运行WebDrive2019软件()
{
	IfWinNotExist,WebDrive 2019 ahk_exe WebDrive.exe
	{
		Process,Close,WebDrive.exe
		Run,"C:Program FilesWebDriveWebDrive.exe"
	}
	else
		SetTimer,运行WebDrive2019软件,Delete
}
;
激活WebDrive2019软件窗口()
{
	;~ 激活互斥锁定,防止在同一时间激活两个窗口
	IfWinNotActive,ahk_exe WebDrive.exe,Username
	{
		IfWinNotActive,01-单位办公 ahk_class CabinetWClass ahk_exe explorer.exe
		{
			WinActivate,WebDrive 2019 ahk_exe WebDrive.exe
		}
	}
}
;
激活并移动单位办公文件夹窗口()
{
	IfExist,W:1-工作文件夹1-办公1-单位办公
		Run,W:1-工作文件夹1-办公1-单位办公
	WinShow,01-单位办公 ahk_class CabinetWClass ahk_exe explorer.exe
	WinActivate,01-单位办公 ahk_class CabinetWClass ahk_exe explorer.exe
	Sleep,100
	WinMove,01-单位办公 ahk_class CabinetWClass ahk_exe explorer.exe,,A_ScreenWidth/2,20,A_ScreenWidth/2-20,A_ScreenHeight-70
	IfWinActive,01-单位办公 ahk_class CabinetWClass ahk_exe explorer.exe
	{
		;		WinGetPos [, X, Y, Width, Height, WinTitle, WinText, ExcludeTitle, ExcludeText]
		WinGetPos,MyX,MyY,MyWidth,MyHeight,01-单位办公 ahk_class CabinetWClass ahk_exe explorer.exe
		if(MyX=A_ScreenWidth/2)
		{
			if(MyWidth=A_ScreenWidth/2-20)
			{
				WinClose,WebDrive 2019 ahk_exe WebDrive.exe
				ToolTip
				SetTimer,判断WebDrive2019软件是否已经安装,Delete
				SetTimer,运行WebDrive2019软件,Delete
				SetTimer,激活WebDrive2019软件窗口,Delete
				SetTimer,激活并移动单位办公文件夹窗口,Delete
			}
	}
}
}
;
02激活或隐藏窗口EmEditor()
{
	;~ SetTimer,Timer激活或隐藏窗口EmEditor,500
	根据窗口类名激活或者隐藏窗口()
}
;
03激活或隐藏窗口MasterSeeker()
{
	;~ MsgBox,Everything热键函数被触发 ;不知道为什么,有时候Win+F热键会被操作系统夺回去
	SetTimer,Timer激活或隐藏窗口MasterSeeker,500
}
;
Timer激活或隐藏窗口MasterSeeker()
{
	WinGetActiveTitle,MSTitle
	IfInString,MSTitle,MasterSeeker
	{
		WinHide,ahk_exe MasterSeeker.exe
		SetTimer,Timer激活或隐藏窗口MasterSeeker,Delete
	}
	else
	{
		IfWinNotExist,ahk_exe MasterSeeker.exe
		{
			IfExist,D:greenMasterSeekerMasterSeeker.exe
			{
				Run,D:greenMasterSeekerMasterSeeker.exe
			}
		}
		;
		loop,3
		{
			WinShow,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
			WinActivate,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
			WinWaitActive,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
			ControlFocus,Filename,MasterSeeker 1.5.1 by DxCK ahk_exe MasterSeeker.exe
			Sleep,10
		}
		Send,^a
		SetTimer,Timer激活或隐藏窗口MasterSeeker,Delete
	}


	;~ 根据窗口类名激活或者隐藏窗口("Everything","EVERYTHING")
	;----- 全选激活MasterSeeker窗口的搜索编辑框:
	;~ WinGetActiveTitle,MTitle
	;~ IfInString,MTitle,Everything
	;~ if(MTitle=="Everything")
	;~ {
	;~ SetTimer,Timer激活或隐藏窗口Everything,Delete
	;~ WinWaitActive,ahk_class EVERYTHING
	;~ Sleep,10
	;~ loop,3
	;~ {
	;~ ControlFocus,Edit1,Everything ahk_class EVERYTHING
	;~ Sleep,10
	;~ ControlSend,Edit1,{End}{ShiftDown}{Home}{ShiftUp},Everything ahk_class EVERYTHING
	;~ Sleep,10
	;~ }
	;~ }
}
;
04激活或隐藏窗口SogouExplorer()
{
	{
		ToolTip,正在启动搜狗高速浏览器_请稍候 . . .
		SetTimer, RemoveToolTip, 3000
	}
根据窗口类名激活或者隐藏窗口("SogouExplorer","SE_SogouExplorerFrame")
}
;
05激活或隐藏窗口TotalCommander()
{
	if (A_Is64bitOS=1)
		根据窗口类名激活或者隐藏窗口("TotalCMD64","TTOTAL_CMD")
	else
		根据窗口类名激活或者隐藏窗口("TotalCMD","TTOTAL_CMD")
}
;
06激活或隐藏窗口计算器Calc()
{
	Run,calc
}
;
07用SciTE4AutoHotkey编辑此脚本()
{
	IfExist,%ProgramDir%AutoHotkeySciTESciTE.exe
		Run,%ProgramDir%AutoHotkeySciTESciTE.exe %A_ScriptName%
	else
	{
		{
			ToolTip,找不到文件%ProgramDir%AutoHotkeySciTESciTE.exe ,% A_ScreenWidth/2-150,% A_ScreenHeight/2-150
			SetTimer, RemoveToolTip, 3000
		}
		Sleep,3000
}
}
;
08重启此脚本()
{
	Reload
}
;
09终止此脚本执行()
{
	{
		ToolTip,%A_ScriptName% (即此脚本)已经退出
		SetTimer, RemoveToolTip, 500
	}
Sleep,500
ExitApp
}
;
10设置此脚本的运行参数()
{
#SingleInstance,force ;当此脚本已经运行时自动替换旧实例再次运行。
#Persistent  ;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
#NoEnv  ;不检查空变量是否为环境变量(建议所有新脚本使用)。
#WinActivateForce  ;用强制的方法激活窗口。阻止任务栏按钮的闪烁.
	;~ #NoTrayIcon  ;不显示托盘图标。
	;~ #Warn
	SetWorkingDir,%A_ScriptDir%  ;改变脚本的当前工作目录。
	DetectHiddenWindows,On  ;设置脚本可以“看见”隐藏的窗口。
	SetTitleMatchMode,2  ;窗口标题匹配模式改成某个位置必须包含WinTitle。
	SendMode,Input  ;SendInput 通常更快更可靠. 缓存了发送期间任何物理的键盘或鼠标活动, 避免了在发送时夹杂用户的键击.
	CoordMode,Mouse,Screen
	CoordMode,Pixel,Screen
	CoordMode,ToolTip,Screen
	ListLines,Off
	SetBatchLines,-1
	SetStoreCapsLockMode, On

	;~ SetBatchLines,
	;~ SetKeyDelay,
	;~ SetWinDelay,
	;~ SetControlDelay,
}
;
11设置此脚本用户自定义变量()
{
	;~ global 移动硬盘盘符 ;带冒号:
}
;
12防止重复运行此脚本()
{
#SingleInstance,force
	loop,33
	{
		DetectHiddenWindows,On
		Sleep,33
		IfWinExist,QQ595076941_AutoRunAHK
			ExitApp
	}
	Gui, Show, Hide,QQ595076941_AutoRunAHK
}
;
; 请使用 窗口信息工具 AHKInfo 1.3.5 获取窗口的类名
根据窗口类名激活或者隐藏窗口(VarExeFileName:="EmEditor",VarWinClassName:="EmEditorMainFrame3")
{
	; 1、如果程序没有运行则运行程序
	Process,Exist,%VarExeFileName%.exe
	if (%ErrorLevel%=0)
	{
		IfExist,%ProgramDir%%VarExeFileName%%VarExeFileName%.exe
		{
			Run,%ProgramDir%%VarExeFileName%%VarExeFileName%.exe
			return
		}
		else
		{
			MsgBox,找不到文件 %ProgramDir%%VarExeFileName%%VarExeFileName%.exe
			return
		}
	}
	; 2、如果窗口未置顶则显示并激活(切换到)指定窗口
	IfWinNotActive,ahk_class %VarWinClassName%
	{
		loop,3
		{
			WinShow,ahk_class %VarWinClassName%
			;~ WinMaximize,ahk_class %VarWinClassName%
			WinGet, WinID, ID,ahk_class %VarWinClassName%
			DllCall("SwitchToThisWindow", "UInt", WinID, "UInt", 1)
		}
		return
	}
	; 3、如果窗口已经显示并置顶则隐藏窗口
	;~ WinMinimize,ahk_class %VarWinClassName%
	WinHide,ahk_class %VarWinClassName%
}
IfExistRun(TargetEXE) ;检查文件是否存在并运行程序
{
	IfExist,%ProgramDir%%TargetEXE%%TargetEXE%.exe
		Run,%ProgramDir%%TargetEXE%%TargetEXE%.exe
	else
	{
		ToolTip,未找到文件%ProgramDir%%TargetEXE%%TargetEXE%.exe
		SetTimer, RemoveToolTip, 3000
	}
}
RemoveToolTip:
	SetTimer, RemoveToolTip, Off
	ToolTip
return
;

;  ;智能命令,双击ALT执行
;  Alt::
;  	if winc_presses > 0 ; SetTimer 已经启动, 所以我们记录键击.
;  	{
;  		winc_presses += 1
;  		return
;  	}
;  	; 否则, 这是新开始系列中的首次按下. 把次数设为 1 并启动
;  	; 计时器:
;  	winc_presses = 1
;  	SetTimer, KeyWinC, -400 ; 在 400 毫秒内等待更多的键击.
;  return
;
;  ;双击执行跳转
;  KeyWinC:
;  	if winc_presses = 2 ; 此键按下了两次.
;  	{
;  		Gui, Show
;
;  	}
;  	; 不论触发了上面的哪个动作, 都对 count 进行重置
;  	; 为下一个系列的按下做准备:
;  	winc_presses = 0
;  return


; 00打开随身U盘_办公专用盘()
; {
; 	随身U盘的盘符:=搜索随身U盘并设置盘符()
; 	if (随身U盘的盘符<>0)
; 	{	ToolTip
; 		FileCreateDir,	%随身U盘的盘符%:1_办公文件
; 		DetectHiddenWindows,On
; 		SetTitleMatchMode,2
; 		;~ 需要设置一下系统,工具->文件夹选项->查看->在标题栏显示完整路径
; 		IfWinExist,9.22
; 		{
; 			WinShow,9.22
; 			WinActivate,9.22
; 			WinMaximize,9.22
; 		}
; 		else
; 		{
;
; 			IfExist,D:ProgramTotalCMDTotalCMD.exe
; 			{
; 				Run,D:ProgramTotalCMDTotalCMD.exe %随身U盘的盘符%:1_办公文件
; 			}
; 			else
; 				MsgBox,找不到文件 D:ProgramTotalCMDTotalCMD.exe
; 			;~ Run,%随身U盘的盘符%:1_办公文件
; 		}
; 		loop,5
; 		{
; 			WinMove,01_办公文件 ahk_class CabinetWClass,,A_ScreenWidth/2,0,A_ScreenWidth/2,A_ScreenHeight-35
; 			Sleep,100
; 		}
; 	}
; 	else
; 		ToolTip,没有找到随身U盘
;       SetTimer, RemoveToolTip, 3000
; }
; ;
;  00打开随身办公专用U盘()
;  {
;  	; 检测操作是否成功的定时器周期应当大于操作定时器的周期(即500大于100)
;  	SetTimer,AllMissionComplete,500
;  	SetTimer,OpenWorkFolder,100
;  	SetTimer,ActivateWorkFolder,100
;  	SetTimer,ReSizeWorkFolder,100
;  }
;  ;
;  AllMissionComplete()
;  {
;  	if(OpenCount >100)
;  	{
;  		SetTimer,AllMissionComplete,Delete
;  		SetTimer,OpenWorkFolder,Delete
;  		SetTimer,ActivateWorkFolder,Delete
;  		SetTimer,ReSizeWorkFolder,Delete
;  		ToolTip,没有找到随身U盘_请连接随身U盘到电脑
;  		SetTimer, RemoveToolTip, 3000
;  	}
;  IfWinActive,,01_办公文件
;  {
;  	WinGetPos,X,Y,,,,01_办公文件
;  	if(A_ScreenWidth/2-X=0)
;  	{
;  		SetTimer,AllMissionComplete,Delete
;  		SetTimer,OpenWorkFolder,Delete
;  		SetTimer,ActivateWorkFolder,Delete
;  		SetTimer,ReSizeWorkFolder,Delete
;  	}
;  }
;  	Hotkey,``,00打开随身办公专用U盘
;  }
;  ;
;  OpenWorkFolder()
;  {
;  	OpenCount++
;  	IfWinNotExist,,01_办公文件
;  	{
;  		DriveGet,DriveList,List
;  		loop,Parse,DriveList
;  		{
;  			DriveGet,USBDriveLabel,Label,%A_LoopField%:
;  			IfInString,USBDriveLabel, 随身U盘
;  			{
;  				FileCreateDir,%A_LoopField%:1_办公文件
;  				Run,%A_LoopField%:1_办公文件
;  			}
;  		}
;  	}
;  }
;  ;
;  ActivateWorkFolder()
;  {
;  	WinShow,,01_办公文件
;  	WinActivate,,01_办公文件
;  }
;  ;
;  ReSizeWorkFolder()
;  {
;  	WinMove,,01_办公文件,A_ScreenWidth/2,0,A_ScreenWidth/2,A_ScreenHeight-35
;  }
;
; ===== 脚本结束 =====

 

;~ %A_ScriptDir%scripts无窗口全局热字串定义.ahk

; 用AutoHotkey的热字串功能启动常用电脑程序软件 Version 2 Build 20191214

; 电脑上的快捷键太多了,记都记不住,容易冲突和搞混,所以做了个热字串启动
; 用法:运行此脚本后在键盘上输入字符串  /np
; 此脚本的写作和调试完成日期:2019年12月12日
; 此脚本的作者:徐晓亮 (aahk)
; 此脚本作者的腾讯QQ电子邮箱地址:595076941@QQ.com

#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.
#SingleInstance,force ;当此脚本已经运行时自动替换旧实例再次运行。
#Persistent  ;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
DetectHiddenWindows,On  ;设置脚本可以“看见”隐藏的窗口。
SetTitleMatchMode,2  ;窗口标题匹配模式改成某个位置必须包含WinTitle。
;
; 设置插入当前日期和时间的热字串WT ( What is the time now )
Sleep,500
::wt::
Sleep,500
	ClipSaved := ClipboardAll   ; 把剪贴板的所有内容保存到您选择的变量中
	NowTimeString =%A_YYYY%%A_MM%%A_DD%
	Clipboard :=NowTimeString
	Send ^v
	Sleep,500
	Clipboard := ClipSaved   ; 恢复剪贴板为原来的内容. 注意这里使用 Clipboard (不是 ClipboardAll).
	ClipSaved =   ; 在原来的剪贴板含大量内容时释放内存.
return
;
; 运行此脚本后在键盘上输入 `np 打开记事本程序 , `键位于Esc和Tab键之间(即波浪号~所在的键)
:*:``no::
:*:``np::
	IfExist,C:WindowsNotepad.exe
	{
		Run,C:WindowsNotepad.exe
	}
	else
	{
		MsgBox,没有找到记事本程序可执行文件C:WindowsNotepad.exe
	}
	ToolTip,正在启动记事本请稍后...
	SetTimer, RemoveToolTip, 3000
return
;
return
;
:*:``em::
:*:``ee::
	Hotstrings("EmEditor")
return
;
:*:``ma::
:*:``ms::
	Hotstrings("MasterSeeker")
return
;
:*:``so::
:*:``sg::
	Hotstrings("SogouExplorer")
return
;
:*:``to::
:*:``tc::
	Hotstrings("TotalCMD")
return
;
:*:``qq::
	Hotstrings2("qq")
return
;
Hotstrings(ExeName)
{

	IfExist,D:green%ExeName%%ExeName%.exe
	{
		Run,D:green%ExeName%%ExeName%.exe
	}
	else
	{
		MsgBox,没有找到可执行文件D:Program%ExeName%%ExeName%.exe
	}
	ToolTip,正在启动%ExeName%_请稍后...
	SetTimer, RemoveToolTip, 3000
}
;
Hotstrings2(ExeName2)
{
	IfExist,D:green%ExeName2%Bin%ExeName2%.exe
	{
		Run,D:green%ExeName2%Bin%ExeName2%.exe
	}
	else
	{
		MsgBox,没有找到可执行文件D:Program%ExeName2%Bin%ExeName2%.exe
	}
	ToolTip,正在启动%ExeName2%_请稍后...
	SetTimer, RemoveToolTip, 3000
}

; ===== 函数定义段 =====
打开随身U盘()
{
	随身U盘的盘符:=搜索随身U盘并设置盘符()
	if (随身U盘的盘符<>0)
	{
		SetTimer, RemoveToolTip, 5000
		FileCreateDir, %随身U盘的盘符%:1_办公文件
		DetectHiddenWindows,On
		SetTitleMatchMode,2
		;~ 需要手动或用脚本语句设置一下系统,工具->文件夹选项->查看->在标题栏显示完整路径
		IfWinExist,,01_办公文件
		{
			WinShow,,01_办公文件
			WinActivate,,01_办公文件
		}
		else
		{
			Run,%随身U盘的盘符%:1_办公文件
		}
		loop,5
		{
			WinMove,,01_办公文件,A_ScreenWidth/2,0,A_ScreenWidth/2,A_ScreenHeight-35
			Sleep,100
		}
	}
	else
		ToolTip,没有找到随身U盘
	SetTimer, RemoveToolTip, 5000
}
;
; 根据磁盘卷标搜索到盘符后,可以再使用 IfExist 命令检查文件或文件夹是否存在。先检测,后执行。
搜索随身U盘并设置盘符()
{ 找到U盘:=false
	DriveGet,盘符清单,List
	loop,Parse,盘符清单
	{ DriveGet,卷标,Label,%A_LoopField%:
		IfInString,卷标, 随身U盘
		{ 找到U盘:=true
			return,%A_LoopField%
		}
	}
	if (not 找到U盘)
	{ return,0
	}
}
;
;
RemoveToolTip:
	SetTimer, RemoveToolTip, Off
	ToolTip
return
; ===== 源代码备份网址 =====
; https://www.cnblogs.com/delphixx/p/12033306.html
; http://autohotkey.bokee.com/507502269.html
; ===== 脚本结束 =====

 

Everything和MasterSeeker常驻内存,加快文件搜索窗口的显示和隐藏的反应速度。

 

;~ %A_ScriptDir%scripts设置常驻内存的程序加快窗口显示的速度.ahk
;
global ProgramDir
;~ ProgramDir=%A_ScriptDir%......
ProgramDir=D:green
SetTimer,1设置此脚本的运行参数,-1000
;~ SetTimer,14设置此脚本用户自定义变量,-1000
SetTimer,2防止重复运行此脚本,-1000
SetTimer,3保持Everything窗口常驻内存从而提高显示速度,5000
return
;
1设置此脚本的运行参数()
{
#SingleInstance,force ;当此脚本已经运行时自动替换旧实例再次运行。
#Persistent  ;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
#NoEnv  ;不检查空变量是否为环境变量(建议所有新脚本使用)。
#WinActivateForce  ;用强制的方法激活窗口。阻止任务栏按钮的闪烁.
	;~ #NoTrayIcon  ;不显示托盘图标。
	;~ #Warn
	SetWorkingDir,%A_ScriptDir%  ;改变脚本的当前工作目录。
	DetectHiddenWindows,On  ;设置脚本可以“看见”隐藏的窗口。
	SetTitleMatchMode,2  ;窗口标题匹配模式改成某个位置必须包含WinTitle。
	SendMode,Input  ;SendInput 通常更快更可靠. 缓存了发送期间任何物理的键盘或鼠标活动, 避免了在发送时夹杂用户的键击.
	CoordMode,Mouse,Screen
	CoordMode,Pixel,Screen
	CoordMode,ToolTip,Screen
	ListLines,Off
	SetBatchLines,-1
	SetStoreCapsLockMode, On

	;~ SetBatchLines,
	;~ SetKeyDelay,
	;~ SetWinDelay,
	;~ SetControlDelay,
}
;
2防止重复运行此脚本()
{
#SingleInstance,force
	loop,33
	{
		DetectHiddenWindows,On
		Sleep,33
		IfWinExist,QQ595076941_AutoRunAHK_ram
			ExitApp
	}
	Gui, Show, Hide,QQ595076941_AutoRunAHK_ram
}
;
3保持Everything窗口常驻内存从而提高显示速度()
{
	Process,Exist,Everything.exe
	if (%ErrorLevel%=0)
	{
		IfWinNotExist,Everything
		{
			IfWinNotExist,ahk_class EVERYTHING
			{
				IfWinNotExist,ahk_exe Everything.exe
				{
					IfExist,%ProgramDir%EverythingEverything.exe
						Run,%ProgramDir%EverythingEverything.exe
					WinWait,ahk_class EVERYTHING
					loop,3
					{
						WinHide,ahk_class EVERYTHING
						Sleep,50
					}
				}
			}
		}
	}
	;~ Process,Exist,MasterSeeker.exe
	;~ if (%ErrorLevel%=0)
	;~ {
	;~ IfWinNotExist,MasterSeeker 1.5.1 by DxCK
	;~ {
	;~ IfWinNotExist,ahk_exe MasterSeeker.exe
	;~ {
	;~ IfExist,%ProgramDir%MasterSeekerMasterSeeker.exe
	;~ Run,%ProgramDir%MasterSeekerMasterSeeker.exe
	;~ WinWait,ahk_class WindowsForms10.Window.8.app.0.218f99c
	;~ loop,3
	;~ {
	;~ WinHide,ahk_class WindowsForms10.Window.8.app.0.218f99c
	;~ Sleep,100
	;~ }
	;~ }
	;~ }
	;~ }
}
;
; #####################################################################
;
; 此脚本到此行结束

 

;~ 8删除暂时无用的垃圾文件

#SingleInstance,force
#Persistent
#NoEnv
DetectHiddenWindows,On
SetTitleMatchMode,2

SetTimer,8删除暂时无用的垃圾文件,5000
return

8删除暂时无用的垃圾文件()
{
	FileDelete,D:PersonalDesktop委托交易.lnk
	FileDelete,C:UsersPublicDesktop委托交易.lnk
	FileDelete,C:UsersAdministratorDesktop委托交易.lnk
}

 

;~ 9键盘鼠标闲置无操作3分钟后关闭显示器闲置4分钟后锁定电脑桌面
;~ 系统设置:关闭显示器电源5分钟,屏幕保护6分钟
;当此脚本已经运行时自动替换旧实例再次运行。
#SingleInstance,force
;让脚本持久运行(即直到用户关闭或遇到 ExitApp)。
#Persistent
;
SetTimer,ScreenOff,1000
SetTimer,ScreenLock,1000
return
;
; 控制面板设置,关闭显示器5分钟,屏幕保护空白等待6分钟并选中在恢复时显示登录屏幕
; 此脚本设置, 关闭显示器7分钟,等待8分钟锁定屏幕

ScreenOff()
{
	;超时毫秒数,7*60*1000=420000,1秒=1000毫秒
	if(A_TimeIdlePhysical>420000)
	{
		if(A_TimeIdle>420000)
		{
			;~ 关闭显示器
			SendMessage, 0x112, 0xF170, 2,, Program Manager
		}
}
}
;
ScreenLock()
{
	;超时毫秒数,8*60*1000=480000,1秒=1000毫秒
	if(A_TimeIdlePhysical>480000)
	{
		if(A_TimeIdle>480000)
		{
			;~ 锁定电脑桌面
			Run,C:WindowsSystem32Rundll32.Exe user32.dll LockWorkStation
		}
}
}

 

桌面文件夹权限设置为只读,只在群晖NAS中新建和编辑文档,或者延时从定向桌面到群晖网络共享位置或共享映射虚拟磁盘文件夹。或者用GoodSync同步到群晖NAS。

 

用脚本备份、删除、恢复桌面的默认图标和默认图标的显示坐标位置,长期保持桌面图标,系统全局快捷键,操作系统软件和应用软件配置设置长期固定不变。

 

;~ 桌面图标清理和恢复


;~ 清理桌面图标
;~ FileDelete,D:PersonalDesktop*.*



;~ 恢复默认的桌面图标
FileCopy,D:greenAHKManagerLnks*.*,D:PersonalDesktop,0

;~ %~dp0greenRobocopyrobocopy.exe %~dp0green D:green *.* /E /R:1 /V /W:1 /X /ZB

;~ /MIR :: 镜像目录树(等同于/E 和/PURGE)。

;~ Robocopy.exe 是 微软在Windows server 2003 Resource Kit Tools 里面提供的程序来做备份的,Windows Vista系统中已经自带了这个命令行程序。
;~ 复制选项 /MIR :: 镜像目录树(等同于/E 和/PURGE)。

Run %comspec% /c  ""C:WindowsSystem32Robocopy.exe D:greenAHKManagerLnks*.*  D:PersonalDesktop  *.lnk *.url *.bat  /MIR""

 

所有台式电脑、笔记本电脑、平板电脑、智能手机都具有完全相同或非常近似的桌面、配置、热键、脚本、环境,如需修改安装配置脚本或者功能运行脚本只需要修改群晖主要NAS服务器上的脚本就可以了(因为设备在启动时会全自动静默连接群晖并全自动静默下载最新版本的脚本源代码和相关资源文件,所以无需到每台电脑或手机上分别更新源代码版本,一切都是那么全自动化(Autoruns),那么智能化(If、SetTimer)。请舒舒服服的享受全自动静默智能化脚本带来的工作、生活和娱乐等各方面的高效便捷的部署和操作(传感器、物联网、区块链、脚本、容灾、冗余)。)

 

或者

利用 Synology High Availability (SHA) 来提供镜像数据,充分延长服务正常运行时间。

给TA捐赠
共{{data.count}}人
人已捐赠
其他

电子文件存储方案20210318

2021-3-18 17:12:06

其他

如何高效的搜索AutoHotkey脚本源代码文件?

2021-3-28 16:59:19

3 条回复 A文章作者 M管理员
  1. aahk

    还是会吃掉源代码中的斜杠符号,只能科学研究,不能复制测试,有点可惜了。

  2. aahk

    传感器和物联网 还有区块链 主要用于环境感知判断和分布式容灾存储(去中心化存储)以及最主要的距离身份验证

    当传感器发现用户与设备的无线电传输距离大于设定值(10米)时立即通知AutoHotkey脚本和Delphi程序锁定电脑桌面和相关的应用程序,当传感器发现(定时器巡检)用户(红外线活体人类)与设备(电脑、手机、服务器或者其他智能设备)的无线电传输距离小于等于设定值(10米)时立即全自动静默解锁电脑桌面和相关的应用程序。

    设备的登录解锁和闲置超时用户超距锁定对于用户来说是透明的,用户无法感知锁定和解锁的过程,因为锁定和解锁的过程是透明的,全自动的,智能的,后台的,完全无人值守的操作。类似于汽车的智能钥匙,解锁还是锁定完全取决于用户与设备之间的直线距离,此距离参数通过物理传感器定时测量得到。

个人中心
购物车
优惠劵
有新私信 私信列表
搜索