[FUNC]RunOrActivate

来源:互联网 发布:电脑usb端口上的电涌 编辑:程序博客网 时间:2024/04/25 02:09
;===========================================================================; Run a program or switch to it if already running.;     Target - Program to run. E.g. Calc.exe or C:\Progs\Bobo.exe;     WinTitle - Optional title of the window to activate. Programs like;        MS Outlook might have multiple windows open (main window and email;        windows). This parm allows activating a specific window.;;Original Source comes from forum on http://www.autohotkey.com;Optimized by alongside (http://hi.baidu.com/alongside) @ 2007-04-26; ===========================================================================RunOrActivate(Target, WinTitle = ""){   ; Get the filename without a path   SplitPath, Target, TargetNameOnly   Process, Exist, %TargetNameOnly%   If ErrorLevel > 0      PID = %ErrorLevel%   Else      Run, %Target%, , , PID   If WinTitle <>   {      SetTitleMatchMode, 2      WinWait, %WinTitle%, , 3      WinActivate, %WinTitle%   }   Else   {      WinWait, ahk_pid %PID%, , 3      WinActivate, ahk_pid %PID%   }}Return; Example uses...#`::RunOrActivate("taskmgr")          ;Run Task;~ #1::RunOrActivate("D:\download")     ;Mend to your own folders#1::RunOrActivate("D:\abc")     ;Mend to your own folders#f::RunOrActivate("D:\Program Files\Mozilla Firefox\firefox.exe")    ;Mend to your own programs#y::RunOrActivate("wmplayer.exe")     ;Run WindowsMediaplayer#-::RunOrActivate("mspaint.exe")#=::RunOrActivate("calc.exe") 

0 0
原创粉丝点击