autohotkey AHK:启动/停止的Oracle服务

AHK:自动启动/停止的Oracle服务

Oracle服务.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 双击快速启动/停止Oracle服务
; 
; gaochao.morgen@gmail.com
; 2014/2/24
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#Include ../lib/StdoutToVar.ahk

#SingleInstance Force
#NoTrayIcon
#NoEnv

Gui, Font,, Arial
Gui, Font, s10
Gui, Add, ListView, -Multi x2 y0 w350 h350 gFastOperate, Index|Service|Status

; 刷新ListView
Gosub, REFRESH

Gui, Show,, Oracle Service List
Return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; 刷新ListView
REFRESH:
	LV_Delete()	; 清空列表内容

	scCmd := "sc.exe queryex state= all"	; 获取所有服务的数据
	sc := StdoutToVar_CreateProcess(scCmd)	; 命令输出从stdout定向到变量中
	idx := 0
	pos := 0
	
	Loop, Parse, sc, `n, `r
	{
		If A_LoopField=
			Continue
		IfInString, A_LoopField, SERVICE_NAME:
		{
			StringGetPos, pos, A_LoopField, :
			pos+=1
			StringTrimLeft, service_name, A_LoopField, %pos%
			Continue
		}
		IfInString, A_LoopField, STATE              :
		{
			StringGetPos, pos, A_LoopField, :
			pos+=6
			StringMid, state, A_LoopField, %pos%, 7
			StringLower, state, state, T
			IfInString, service_name, OracleService		; 过滤Oracle服务
			{
				idx++
				LV_Add("", idx, service_name, state)
			}
			;IfInString, service_name, OracleOraDb11g_home1TNSListener	; 过滤Listener
			IfInString, service_name, TNSListener	; 过滤Listener
			{
				idx++
				LV_Add("", idx, service_name, state)
			}
			Continue
		}
	}
	
	LV_ModifyCol()  ; 根据内容自动调整每列的大小
Return

; 双击时快速切换服务状态(未启动则启动,已启动则关闭)
FastOperate:
	if A_GuiEvent = DoubleClick
	{
	    LV_GetText(SrvName, A_EventInfo, 2)		; 从第二个字段中获取文本.
	    LV_GetText(SrvStatus, A_EventInfo, 3)	; 从第三个字段中获取文本.
		if (SrvStatus = "Running")
		{
			RunWait, cmd /c net stop %SrvName%
			Gosub, REFRESH
		}
		else
		{
			RunWait, cmd /c net start %SrvName%
			Gosub, REFRESH
		}
	}
Return

; 当窗口关闭时, 自动退出脚本
GuiClose:
	Gui, Destroy
ExitApp

autohotkey AHK:一键启动软件,可以指定第几秒启动哪个程序

AHK:一键启动软件,可以指定第几秒启动哪个程序

runSoft.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 一键启动办公必备程序
; 需要人为指定第几秒启动哪个程序
; 
; gaochao.morgen@gmail.com
; 2013/7/2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#SingleInstance Force
#NoEnv

; 设置 ErrorLevel 为这个正在运行脚本的 PID
Process, Exist

ExeList := Object()

; 采用Object.Insert(Index, Value)的方式,Index表示第几秒启动,Value表示程序
ExeList.Insert(0, "E:\DeskWidget\DeskWidget.exe")
ExeList.Insert(5, "C:\Program Files\Tencent\QQ\QQProtect\Bin\QQProtect.exe")
ExeList.Insert(15, "C:\Program Files\Microsoft Office Communicator\communicator.exe")
ExeList.Insert(20, "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE")
ExeList.Insert(25, "C:\Program Files\DeskTask\DeskTask.exe")

; 采用Object.Insert(Key, Value)的方式,将会按照Key排序,不会按照我设定的顺序启动
/*
 ExeList.Insert("E:\DeskWidget\DeskWidget.exe", 2)
 ExeList.Insert("C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE", 4)
 ExeList.Insert("C:\Program Files\DeskTask\DeskTask.exe", 5)
 ExeList.Insert("C:\Program Files\Microsoft Office Communicator\communicator.exe", 30)
 ExeList.Insert("C:\Program Files\Tencent\QQ\QQProtect\Bin\QQProtect.exe", 5)
 */

Delay := 0
Elapse := 0

for Seconds, Target in ExeList
{
	Delay := (Seconds - Elapse) * 1000
	SplitPath, Target, ProcName

	CoordMode, ToolTip, Screen  ; 把ToolTips放置在相对于屏幕坐标的位置
	ToolTip, Launching %ProcName%, (A_ScreenWidth/2-100), A_ScreenHeight/2
	Sleep, 1000

	; 若进程未启动则启动,若已启动则不作任何改动
	Process, Exist, %ProcName%
	if (ErrorLevel = 0)
	{
		Sleep, %Delay%
		Run, %Target%
	}

	Elapse := ((Seconds-1)>0)?Seconds:0
}

ExitApp	

autohotkey AHK:根据不同的程序设置不同的输入法

AHK:根据不同的程序设置不同的输入法

autoSwitcherIME3.ahk
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AHK版本:    1.1.23.01
; 语言:   中文
; 作者:   lspcieee <lspcieee@gmail.com>
; 网站:   http://www.lspcieee.com/
; 脚本功能: 自动切换输入法
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;=====分组配置
;中文输入法的分组
GroupAdd,cn,ahk_exe QQ.exe  ;QQ
GroupAdd,cn,ahk_exe WINWORD.EXE ;word
GroupAdd,cn,ahk_exe MindManager.exe

;英文输入法的分组
GroupAdd,en,ahk_exe devenv.exe  ;Visual Studio
GroupAdd,en,ahk_exe dopus.exe 
GroupAdd,en,ahk_class Notepad++

;编辑器分组
GroupAdd,editor,ahk_exe devenv.exe  ;Visual Studio
GroupAdd,editor,ahk_exe notepad.exe ;记事本
GroupAdd,editor,ahk_class Notepad++




;函数
;从剪贴板输入到界面
sendbyclip(var_string)
{
    ClipboardOld = %ClipboardAll%
    Clipboard =%var_string%
  ClipWait
    send ^v
    sleep 100
    Clipboard = %ClipboardOld%  ; Restore previous contents of clipboard.
}


setChineseLayout(){
  ;发送中文输入法切换快捷键,请根据实际情况设置。
  send {Ctrl Down}{Shift}
  send {Ctrl Down},
  send {Ctrl Down}{Shift}
  send {Ctrl Down},
  send {Ctrl Up}
}
setEnglishLayout(){
  ;发送英文输入法切换快捷键,请根据实际情况设置。
  send {Ctrl Down}{Shift}
  send {Ctrl Down},
  send {Ctrl Down}{Shift}
  send {Ctrl Down},

  send {Ctrl Down}{Space}
  send {Ctrl Up}
}

;监控消息回调ShellMessage,并自动设置输入法
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage")

ShellMessage( wParam,lParam ) {
  If ( wParam = 1 )
  {
    WinGetclass, WinClass, ahk_id %lParam%
    ;MsgBox,%Winclass%
    Sleep, 1000
    WinActivate,ahk_class %Winclass%
    ;WinGetActiveTitle, Title
    ;MsgBox, The active window is "%Title%".
    IfWinActive,ahk_group cn
    {
      setChineseLayout()
      TrayTip,AHK, 已自动切换到中文输入法
      return
    }
    IfWinActive,ahk_group en
    {
      setEnglishLayout()
      TrayTip,AHK, 已自动切换到英文输入法
      return
    }
  }
}

;在所有编辑器中自动切换中英文输入法
#IfWinActive,ahk_group editor
:*:// ::
  ;//加空格 时 切换到中文输入法
  setEnglishLayout()
  sendbyclip("//")
  setChineseLayout()
return
:Z*:///::
  ;///注释时 切换到中文输入法(也可以输入///加空格)
  setEnglishLayout()
  sendbyclip("//")
  SendInput /
  setChineseLayout()
return
:*:" ::
  ;引号加空格 时 切换到中文输入法
  setEnglishLayout()
  SendInput "
  setChineseLayout()
return
:*:`;`n::
  ;分号加回车 时 切换的英文输入法
  setEnglishLayout()
  sendbyclip(";")
  SendInput `n
return
:Z?*:`;`;::
  ;两个分号时 切换的英文输入法
  setEnglishLayout()
return
:Z?*:  ::
  ;输入两个空格 切换的中文输入法
  setEnglishLayout()
  setChineseLayout()
return

#IfWinActive
autoSwitchIME2.ahk
Gui, Add, GroupBox, x6 y4 w230 h10 , 已安装的输入法(双击切换)
Gui, Add, ListView, r20 x6 y24 w230 h120 vListIME gSetIME ,序号|键盘布局|名称
Gui, Add, Button, x6 y144 w80 h30 gPreIME, 上一输入法
Gui, Add, Button, x156 y144 w80 h30 gNextIME, 下一输入法
Gui, Add, Button, x86 y144 w70 h30 gStateIME, 当前状态
; Generated using SmartGUI Creator 4.0
Gui, Show, x397 y213 h190 w247,输入法切换
Gosub,ReadIME
Return
GuiClose:
ExitApp
ReadIME:
LV_ModifyCol(3,300)
Loop,HKEY_USERS,.DEFAULT/Keyboard Layout/Preload, 1, 1
{
    RegRead,Layout
    RegRead,IMEName,HKEY_LOCAL_MACHINE,SYSTEM/CurrentControlSet/Control/Keyboard Layouts/%Layout%,Layout Text
    RegRead,Layout
     ListContent=%A_LoopRegName%丨%IMEName%丨 %Layout%
    LV_Insert(1,"Vis",A_LoopRegName,Layout,IMEName)
}
Return
StateIME:
Result:=DllCall("GetKeyboardLayout","int",0,UInt)
SetFormat, integer, hex
Result += 0
SetFormat, integer, D
MsgBox 当前键盘布局为 %Result%
return

SetIME:
If (A_GuiEvent<>"DoubleClick")
{
    Return
}
Gui,Submit,Nohide
LV_GetText(Layout,A_EventInfo,2)
;~ MsgBox %Layout%

SwitchIME(Layout)
Return

SwitchIME(dwLayout)
{
    DllCall("SendMessage", UInt, WinActive("A"), UInt, 80, UInt, 1, UInt, DllCall("LoadKeyboardLayout", Str, dwLayout, UInt, 1))
}

NextIME:
DllCall("SendMessage", UInt, WinActive("A"), UInt, 80, UInt, 1, UInt, DllCall("ActivateKeyboardLayout", UInt, 1, UInt, 256))
;-- 对当前窗口激活下一输入法
Return
PreIME:
DllCall("SendMessage", UInt, WinActive("A"), UInt, 80, UInt, 1, UInt, DllCall("ActivateKeyboardLayout", UInt, 0, UInt, 256))
;-- 对当前窗口激活上一输入法
Return
autoSwitchIME.ahk
#Persistent

Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage")
Return

ShellMessage( wParam,lParam ) {
If ( wParam = 1 )
  {
    WinGetclass, WinClass, ahk_id %lParam%
    ;希望切到中文输入法的窗口类名
    If Winclass in Notepad2U
    {
      winget,WinID,id,ahk_class %WinClass%
      SetLayout("E0200804",WinID)
      ;系统内安装的输入法代码可以在注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts查到
      ;将0200804替换为你期望切换的输入法代码即可
    }

   If Winclass in ConsoleWindowClass,ListarySearchBox   ;需要关闭中文输入的窗口类名
    {
      winget,WinID,id,ahk_class %WinClass%
      SetLayout("00000804",WinID)
      ;00000804是english代码,系统内安装的输入法代码可以在注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts查到
    }

    ; If Winclass in Notepad2U  ;需要中文输入法英文状态的,窗口类名
    ; {
    ;   winget,WinID,id,ahk_class %WinClass%
    ;   SetLayout("E0200804",WinID)
    ;   SendInput, {Shift}
    ; }

}
}

;设置的函数
SetLayout(Layout,WinID){
DllCall("SendMessage", "UInt", WinID, "UInt", "80", "UInt", "1", "UInt", (DllCall("LoadKeyboardLayout", "Str", Layout, "UInt", "257")))
}

autohotkey Autohotkey日期示例

Autohotkey日期示例

AHK_Dates
:R*?:ddd::
FormatTime, CurrentDateTime,, dd/MM/yy
SendInput %CurrentDateTime%
return
:R*?:xxx::
FormatTime, CurrentDateTime,, yyMMddHHmmss
SendInput %CurrentDateTime%
return
:R*?:aaa::
FormatTime, CurrentDateTime,, yyMMdd
SendInput %CurrentDateTime%
return
:R*?:jjd::
FormatTime, CurrentDateTime,, dd-MM-yy
SendInput %CurrentDateTime%
return
:R*?:yyy::
FormatTime, CurrentDateTime,, dd-MM-yy HH:mm
SendInput %CurrentDateTime%
return

autohotkey collect1

collect1

暂停某个ahk
#F1::  
DetectHiddenWindows, on  
SetTitleMatchMode, 2  
PostMessage, 0x111, 65306,,, 这里写将被暂停的脚本名(员工脚本名).ahk - AutoHotkey  
return  

65305 挂起
65306 暂停
65307退出
65304编辑

autohotkey judge_process

judge_process
[1]
loop
{
	Sleep, 60000 ;设定为每60秒一检查
	return1 := judge_process_title("chrome_page_find1") ;arg1:伴随打开的ahk的匹配字段
	if WinExist("ahk_exe chrome.exe") ;arg2:目标进程
	{
		if  return1=0
		{
			;'MsgBox,'1'
			Run, H:\Program Files (x86)\ahk\chrome_page_find1.ahk ;arg3:伴随打开的ahk的路径
		}
	}
	else
	{
		if  return1<>0
		{
			;MsgBox,'0'
			WinClose,%return1% ahk_class AutoHotkey
		}
	}
}


judge_process_title(reg1){
	DetectHiddenWindows On
	WinGet, AHKWinList, List, ahk_class AutoHotkey
	loop, %AHKWinList%
	{
		AHKWinHWND := AHKWinList%A_Index%
		WinGetTitle, AHKWinTitle, ahk_id %AHKWinHWND%
		;WinGet, AHKWinProcessPath, ProcessPath, ahk_id %AHKWinHWND%
		RegExMatch(AHKWinTitle ,".*?(" reg1 ").*?" ,name)
		if  (name){
			return, AHKWinTitle
			break
		}
		;MsgBox, % "脚本标题:" AHKWinTitle "`n脚本进程路径:" AHKWinProcessPath
	}
	return, 0
}

https://autohotkey.com/docs/commands/Process.htm#ListEx	Process-ahk


[1]设定自启动的时间

folder = F:\Run
Loop, %folder%\*.lnk
{
runwait %folder%\%A_LoopFileName%
; runwait 命令,等一个程序启动完成之后再循环启动下一个程序,直到循环自动退出。
}
ExitApp
; 自动退出

将快捷方式放入F:\Run

autohotkey 标点

punctuation
NumpadEnd:: ;1
Send #
return

NumpadDown:: ;2
Send $
return

NumpadPgDn:: ;3
Send `&
return

NumpadLeft:: ;4
/*text = 
clipboard = %text%
Send ^v
*/
;用复制到剪贴板的方式,能完全按原字符串输出,如果只是send,在中文下输出(),在英文下输出()。但剪贴板的方法,占用剪贴板
Send `(`)
return

NumpadClear:: ;5
Send `/
return

NumpadRight:: ;6
Send \
return

/*
NumpadHome::
text =
clipboard = %text%
Send ^v
return

NumpadUp::
text =
clipboard = %text%
Send ^v
return

NumpadPgUp::
text =
clipboard = %text%
Send ^v
return
*/

autohotkey TMP1

tmp1
https://wyagd001.github.io/zh-cn/docs/commands/Process.htm#ListEx	Process

注释:
; 整行或后半注释
/*
多行注释
*/

escape:
`

if else:
if (){
    
} else if(){
    
}

http://blog.csdn.net/primox/article/details/46877055	AHK的按键 - CSDN博客


[1]函数,传入变量:
如果变量和其他字符串组合,用".*?(" arg1 ").*?",否则用%arg1%

autohotkey 将MediaKey快捷方式添加到普通键盘

将MediaKey快捷方式添加到普通键盘

MediaKeys.ahk
; ^ = Ctrl

; volume up
^Numpad8::Volume_Up

; volume down
^Numpad2::Volume_Down

; volume mute
^Numpad0::Volume_Mute

; previous
^Numpad4::Media_Prev

; pause
^Numpad5::Media_Play_Pause

; next 
^Numpad6::Media_Next


autohotkey NexusFolder.ahk

NexusFolder.ahk
/*

##  NexusFolder.ahk

##

##  Switch default filemanager by launching this script without

##  commandline parameters. If you send a file or folder as a

##  parameter, the folder will open in NexusFile.

##

##  Script by budRich 2013

*/



GoSub, Init



If !FileExist("NexusFile.exe") {

	MsgBox,Move %A_ScriptName% to the same foler as NexusFile.exe.

	ExitApp

}



If !(cmd) {



	RegRead, rchk, HKCR, Drive\shell\NexusFile

	

	If (ErrorLevel=1)

		RegNexus()

	Else

		RegExplorer()



}	Else {



	If !FileExist(cmd) {

		MsgBox,%cmd% does not exist.

		ExitApp

	}


	ExploreFolder(cmd)



}



ExitApp



ExploreFolder(fld) {



	nexTtl := "NexusFile ahk_class TfMain"

	if !WinExist(nexTtl)

		Run, NexusFile.exe



	WinActivate, %nexTtl%

	WinWaitActive, %nexTtl%

	ControlClick, TNXPaintPanel2,%nexTtl%,,right,,NA

	Send,/cd %fld%{Enter}


}



RegNexus() {



	MsgBox, 4,,Do you want to set NexusFile as the default file manager?

	IfMsgBox, Yes

	{ 

		RegWrite, REG_SZ, HKCR, Drive\shell\,,NexusFile

		RegWrite, REG_SZ, HKCR, Drive\shell\NexusFile,, Open in NexusFile

		RegWrite, REG_SZ, HKCR, Directory\shell,,NexusFile

		RegWrite, REG_SZ, HKCR, Directory\shell\NexusFile,, Open in NexusFile



		if !A_IsCompiled

		{	RegWrite, REG_SZ, HKCR, Drive\shell\NexusFile\command,, %A_AhkPath% %A_ScriptFullPath% `%1

			RegWrite, REG_SZ, HKCR, Directory\shell\NexusFile\command,, %A_AhkPath% %A_ScriptFullPath% `%1

		}

		else

		{	RegWrite, REG_SZ, HKCR, Drive\shell\NexusFile\command,, %A_ScriptFullPath% `%1

			RegWrite, REG_SZ, HKCR, Directory\shell\NexusFile\command,, %A_ScriptFullPath% `%1

		}

	}



}



RegExplorer() {



	MsgBox, 4,,Do you want to set Explorer as the default file manager?

	IfMsgBox, Yes

	{ 

		RegWrite, REG_SZ, HKCR, Drive\shell\,,none

		RegDelete, HKCR, Drive\shell\NexusFile,

		RegWrite, REG_SZ, HKCR, Directory\shell,,none

		RegDelete, HKCR, Directory\shell\NexusFile,

	}



}



Init:

#SingleInstance force

#NoEnv

#NoTrayIcon

SetBatchLines, -1

SetWinDelay, -1

SetWorkingDir, %A_ScriptDir%

SendMode, Input

cmd = %1%

return