autohotkey AHK:一键锁屏

AHK:一键锁屏

一键锁屏.ahk
#l::
	; Lock Screen. 模拟Win+L没有成功,执行后Win似乎一直处于按下状态
	Run, %A_WinDir%\System32\rundll32.exe user32.dll LockWorkStation 

	Sleep, 500

	; Power off the screen
	; 0x112: WM_SYSCOMMAND
	; 0xF170: SC_MONITORPOWER
	; 2: the display is being shut off
	SendMessage, 0x112, 0xF170, 2,, Program Manager
Return

autohotkey AHK:在CmdMarkdown中一键插入<center>标签,使图像居中显示

AHK:在CmdMarkdown中一键插入<center>标签,使图像居中显示

cmdMarkdownPicCenter.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 在 CmdMarkdown 中一键插入<center>标签,使图像居中显示
; 
; 快捷键: F9
;
; gaochao.morgen@gmail.com
; 2016/12/14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#Include ../lib/HexDec.ahk

#Persistent
#SingleInstance Force
#NoTrayIcon
#NoEnv

#IfWinActive ahk_class Chrome_WidgetWin_0
F9::
	; hWnd - CmdMarkdown的窗口句柄
	WinGet, hWnd, ID, ahk_class Chrome_WidgetWin_0
	CurrentIME := GetCurrentIME(hWnd)
	SetEnglishIME(hWnd)

	; 为当前行加入<center></center>标签对
	Send {Esc}
	Send {RShift}{^}
	Send {}
	SendInput {Raw}i<center>
	Send {Esc}
	Send {RShift}{$}
	SendInput {Raw}a</center>
	Send {Enter 1}

	; 恢复之前的输入法
	SetIME(CurrentIME, hWnd)
Return 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                       函数                            ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; 为指定窗口设置英文输入法
; @param hWnd 窗口句柄
SetEnglishIME(hWnd) {
	SetIME("04090409", hWnd)
}

; 获取指定窗口当前的输入法
; @param hWnd 窗口句柄
; @return 输入法对应的十六进制数字符串,无0x前缀
GetCurrentIME(hWnd) {
	dec := DllCall("GetKeyboardLayout", "UInt", DllCall("GetWindowThreadProcessId", "UInt", hWnd, "UIntp", 0), UInt)
	hex := Dec2Hex(dec)
	StringTrimLeft, layout, hex, 2
	Return layout
}

; 设置指定窗口的输入法
; @param Layout	输入法代码
; @param hWnd	窗口句柄
SetIME(Layout, hWnd) {
	DllCall("SendMessage", "UInt", hWnd, "UInt", "80", "UInt", "1", "UInt", (DllCall("LoadKeyboardLayout", "Str", Layout, "UInt", "257")))
}

autohotkey AHK:自动关闭QQ弹窗

AHK:自动关闭QQ弹窗

自动关闭QQ弹窗.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 自动关闭QQ右下角弹窗
;
; 稻米鼠的板块
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#Persistent
#SingleInstance Force
#NoTrayIcon
#NoEnv

; 若配置文件目录不存在,则创建
LogPath = %A_ScriptDir%\..\log
if (!IsDirExist(LogPath))
	FileCreateDir, %LogPath%

; 日志文件
LogFile = %LogPath%\QQPopLog.txt

SetTimer, KillQQPop, 1000
return

KillQQPop:
	IfWinExist, ahk_class TXGuiFoundation
	{
		;sleep 1000
		WinGetPos, Xpos, Ypos, Width, Height
		if (Width < 400 AND A_ScreenWidth <(Xpos + 500) AND A_ScreenHeight <(Ypos + 500))
		{
			WinGetTitle, Title
			if (StrLen(Title)!= 0 AND Title!= "QQ" AND !(Title~="@") AND !(Title~="(") AND !(Title="TXMenuWindow"))
			{
				WinClose
				;TrayTip,喵了腾讯, 关闭了 %Title%
				file := FileOpen(LogFile, "a")
				file.WriteLine(A_YYYY " " A_MM " " A_DD " " A_Hour ":" A_Min ":" A_Sec " —— " Title  "`n`r")
				file.Close()
				;sleep 1000
				;TrayTip
			}
		}
	}
Return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                       函数                            ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; 判断目录是否存在
IsDirExist(DirName)
{
	if (FileExist(DirName))
	{
		if InStr(FileExist(DirName), "D")
			return true
	}

	return false
}

autohotkey AHK:利用AutoHotkey的进行IE自动化操作

AHK:利用AutoHotkey的进行IE自动化操作,打开网站返回IE对象

ie浏览器自动化控制.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 查看赛迪考勤系统结果
; 
; Chao.Gao@cisdi.com.cn
; 2015/5/26
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#SingleInstance Force
#NoEnv

#Include ../lib/IEAttach.ahk

DOMAIN := "http://cbms.cisdi.com.cn/AQS"

; 先加载空白页面 about:blank , 这样IE窗口应该响应得快一点点
BrowseWebPage("about:blank")

; 考勤系统首页
ie := BrowseWebPage(DOMAIN . "/Login.aspx")
ie.document.getElementById("tbUserID").value := "sa"    ; 设置登录名
ie.document.getElementById("tbUserPsw").value := "sa"   ; 设置密码
ie.document.getElementById("ImageButton1").Click()      ; 点击,登录系统

Sleep, 1000

; 子页面. 登录后直接在子页面上打开新网页,避免处理Cookie
ie := BrowseWebPage(DOMAIN . "/AQSMorning.aspx")
ie.document.getElementById("tbFname").value := "003762" ; 设置登录名
ie.document.getElementById("Button1").Click()           ; 点击查询

; 等待网页加载完成
Loop { 
	Sleep, 200
	if (ie.readyState="complete" or ie.readyState=4 or A_LastError!=0)
		break
}

HWND := ie.HWND
WinSet, AlwaysOnTop, On, %HWND%

Return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;                        函数                           ; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

; 打开一个指定URL的网页,返回IE对象
BrowseWebPage(URL)
{
	ComObjError(false) ; 关闭对象错误提示

    ie := 
    ie := IEAttach(DOMAIN, "URL") ; 试图从打开的IE窗口中找出其对象句柄
	if IsObject(ie)=0 {
		ie := ComObjCreate("InternetExplorer.Application") ; 如果连接IE对象失败就创建一个IE窗口
	}

	; 默认不可见,设为可见
	ie.Visible := true
	ie.Navigate(URL) ; 如果先加载空白页面 about:blank , 这样IE窗口应该响应得快一点点

    ; 等待网页加载完成
	Loop { 
		Sleep, 200
		if (ie.readyState="complete" or ie.readyState=4 or A_LastError!=0)
			break
	}

	Return ie
}

autohotkey AHK:获取当前默认的AHK版本信息

AHK:获取当前默认的AHK版本信息

ahk版本号.ahk
; 判断当前运行的 AutoHotkey Basic/AutoHotkey_L 版本
#SingleInstance Force
#NoTrayIcon
#NoEnv

CheckCurrentVersion()
Return

CheckCurrentVersion()
{
    if (A_AhkVersion = "")
        MsgBox, AutoHotkey Basic, 版本号小于 1.0.22
    else if (A_AhkVersion <= "1.0.48.05")
        MsgBox, AutoHotkey Basic, 版本号为 %A_AhkVersion%
    else
        MsgBox, % "AutoHotkey_L" (A_PtrSize = 4 ? (A_IsUnicode ? " Unicode ":" ANSI "):" 64 位") "版本, 版本号为" A_AhkVersion
    return
}

autohotkey AHK:自动定位注册表位置

AHK:根据剪贴板中的内容自动定位注册表位置

自动定位注册表.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 事先拷贝注册表路径,该脚本直接定位到那个路径
; 
; gaochao.morgen@gmail.com
; 2014/2/4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#SingleInstance Force
#NoTrayIcon
#NoEnv

StringReplace, Clipboard, Clipboard, \, \, All			; 网络文章"\","\"不分
StringReplace, Clipboard, Clipboard, /, \, All			; "/"改为"\"
StringReplace, Clipboard, Clipboard, \\, \, All			; "/"改为"\"
Clipboard := RegExReplace(Clipboard, "\\$", "")			; 若最后一个字符为"\"则去掉

; 本想先探测是否存在改键,但是此方法无法判断出"(默认)"为空的项
;pos := RegExMatch(Clipboard, "HKEY_(.*?)\\", RootKey)	; "我的电脑\HKEY_CURRENT_USER\Software"与"HKEY_CURRENT_USER\Software"一样
;SubKey := SubStr(Clipboard, pos+StrLen(RootKey))
;StringReplace, RootKey, RootKey, \, , All
;
;RegRead, content, %RootKey%, %SubKey%
;if (content = null && ErrorLevel = 1)
;{
;	MsgBox, %Clipboard% is not found.
;	Return
;}

; 关闭已经打开的注册表
IfWinExist, ahk_class RegEdit_RegEdit
{
	WinClose 
    WinWaitClose
}

; 写入
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Applets\Regedit, LastKey, %Clipboard%

; 打开,自动定位到写入位置
Run, regedit,, Max
ExitApp

autohotkey AHK:自动重启的explorer.exe

AHK:自动重启的explorer.exe

自动重启explore.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 重新启动explorer.exe
; 
; gaochao.morgen@gmail.com
; 2013/7/2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#SingleInstance Force
#NoEnv

; 将ErrorLevel置为本脚本PID
Process, Exist

; 获取explorer进程PID,保存在ErrorLevel中
Process, Exist, explorer.exe
PID := ErrorLevel
if (PID)
{
	Process, Close, %PID%
	Process, Wait, %PID%, 5	; 会自动重新启动,如果没有自动重启,则手动重启
	if (ErrorLevel = 0)
		Run, %A_WinDir%\explorer.exe
}
else
{
	Run, %A_WinDir%\explorer.exe
}

autohotkey AHK:一键启动服务窗口

AHK:一键启动服务窗口

一键启动服务窗口.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 一键启动服务窗口
; 
; gaochao.morgen@gmail.com
; 2014/2/4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#Include ../lib/SystemCursor.ahk

#SingleInstance Force
#NoTrayIcon
#NoEnv

OnExit, ShowCursor			; 确保到脚本退出时鼠标光标是显示的.

Run, services.msc			; Max参数不能最大化
Sleep, 800
WinActivate, ahk_class MMCMainFrame
Send {Alt Down}{Space}x		; 测试"!{Space}x"不行,只能让Alt按下
Send {Alt Up}				; 再把Alt弹起
SystemCursor("Off")
ControlGetPos, X, Y,,, SysListView321, ahk_class MMCMainFrame	; 标题栏控件坐标
MouseMove, % X+125, % Y+5	; 控件分隔处
Send {LButton 2}			; 双击,长度最大化
ControlGetPos, X, Y,,, SysListView321, ahk_class MMCMainFrame
MouseMove, % X+300, % Y+300	; 内容区域
Send {LButton}
SystemCursor("On")
Return

ShowCursor:
	SystemCursor("On")
ExitApp

autohotkey AHK:在CMD中快速进入当前目录

AHK:在CMD中快速进入当前目录

CMD目录.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 在CMD中快速进入指定目录
; 1. 如果当前窗口是"我的电脑",则进入当前路径
; 2. 如果不是,则进入剪切板中那个路径
;
; 注意: 打开cmd窗口后会自动输入命令,命令均是英文,因此需要设置默认输入语言为英文
;
; gaochao.morgen@gmail.com
; 2014/4/9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TargetDir := ClipBoard

; 如果"我的电脑"窗口位于最前面,则在CMD中进入"我的电脑"那个路径
IfWinActive, ahk_class CabinetWClass
{
	if A_OSVersion in WIN_7, WIN_8
	{
		; 因为Win7地址栏默认没有展开,所以Edit1的值默认是空的,取ToolbarWindow322代替
		ControlGetText, DirDesc, ToolbarWindow322, A
		pos := RegExMatch(DirDesc, "[^:]*: (.*)", Result)
		if (ErrorLevel = 0 && pos > 0)
			TargetDir := Result1
	}
	else ; WIN_VISTA, WIN_2003, WIN_XP, WIN_2000
	{
		ControlGetText, TargetDir, Edit1, A		; GuiControlGet始终不行
	}
	
}

SplitPath, TargetDir,,,,, OutDrive

Run, cmd.exe,, Max, pid
BringWindowToFront(pid)

SendInput %OutDrive%{Enter}
SendInput {Raw}cd %TargetDir%
SendInput {Enter}
SendInput clear{Enter}	; 3rd/clear.cmd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                   函数                      ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; 让指定进程的窗口置顶
BringWindowToFront(pid)
{
	WinSet, AlwaysOnTop, On, ahk_pid %pid%
	Sleep, 100
	WinSet, AlwaysOnTop, Off, ahk_pid %pid%
}

autohotkey AHK:一键显示或者隐藏文件,后缀名

AHK:一键显示或者隐藏文件,后缀名

一键显隐.ahk
;------------------------------------------------------------------------
; Show hidden folders and file extension in Windows XP
; 注意:
; 	1. 事先确保Hidden=2,同时HideFileExt=1(或者Hidden=1,同时HideFileExt=0)
; 	2. 要修改注册表以实现文件显隐、后缀显隐,因此需要关闭防火墙和杀毒软件才有效果.
;------------------------------------------------------------------------
; User Key: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
; Value Name: Hidden
; Data Type: REG_DWORD (DWORD Value)
; Value Data: (1 = show hidden, 2 = do not show)
;
; User Key: [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
; Value Name: HideFileExt
; Data Type: REG_DWORD (DWORD Value)
; Value Data: (0 = show hidden, 1 = do not show)
;

#SingleInstance Force
#NoEnv

; 文件夹显隐
RegRead, ShowHidden_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden
if ShowHidden_Status = 2
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1
Else
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2

; 后缀名显隐
RegRead, FileExt_Status, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt
If FileExt_Status = 1 
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt, 0
Else 
	RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, HideFileExt, 1

; 获取指定窗口的类名
WinGetClass, CabinetWClass

; 刷新desktop/explorer
PostMessage, 0x111, 28931,,, A
PostMessage, 0x111, 28931,,, ahk_class Progman

; 上述语句在win7中还不能自动刷新,必须模拟一下菜单动作
if A_OSVersion in WIN_7, WIN_8
{
	MouseClick, Right
	Sleep, 1
	Send, {Ctrl Down}e{Ctrl Up}
}