HSDisconnect

;~ =================================================系统定义	 ;{ -- 
		if not A_IsAdmin	{
			Try
			{
				Run *RunAs "%A_ScriptFullPath%"
					ExitApp
			}
		} ;}
#NoEnv	;不检查空变量是否为环境变量 ;{ -- 
;~ #NoTrayIcon
;~ #InstallKeybdHook
;~ #InstallMouseHook
#Persistent
#SingleInstance force
;~ #HotkeyInterval 2000  ; 这是默认值 (毫秒).
;~ #MaxHotkeysPerInterval 200  ;默认70
CoordMode,Pixel,Screen
CoordMode,Mouse,Screen
CoordMode,ToolTip,Screen
SetBatchLines,-1
SetWorkingDir %A_ScriptDir% ;}
;~ =================================================自定义参数部分
Exe=Hearthstone.exe
SplitPath,A_ScriptName , , , , iniFile
IniRead,QuikDis,%iniFile%.ini,Program,QuikDis,2 ;{ -- 
IniRead,TickHSDis,%iniFile%.ini,Program,TickHSDis,6
IniRead,PicX,%iniFile%.ini,PicPos,PicX,Center
IniRead,PicY,%iniFile%.ini,PicPos,PicY,Center
IniRead,PicW,%iniFile%.ini,PicPos,PicW,65
IniRead,MyHK,%iniFile%.ini,Program,MyHK,F8
IniRead,OnTop,%iniFile%.ini,Program,OnTop,1
IniRead,MyRadioGroup,%iniFile%.ini,Program,MyRadioGroup,MyRadioGroup2
;~ IniRead,PicH,%iniFile%.ini,PicPos,PicH
IniRead,Path,%iniFile%.ini,Program,Path
;~ MsgBox % Path
if Path=ERROR
{	
	if !exeGetPath(Exe)
	{
		if FileExist("es.exe") {		
			CmdStr=%A_ScriptDir%\es.exe -s %Exe% ext:exe
			Str:=StdoutToVar_CreateProcess(CmdStr)
			if Str
			{
				;~ MsgBox % Str
				;~ Runwait %comspec% /c %CmdStr%,,hide
				Loop, parse, Str, `n, `r
				{
					;~ MsgBox % A_LoopField
					SplitPath, A_LoopField ,OutFileName
					if (OutFileName=Exe)
					{
;~ MsgBox % Path . A_LoopField
						Path:=A_LoopField
						IniWrite,%Path%,%iniFile%.ini,Program,Path
					}
				}
			}			
		}
	}	
}
if !FileExist(Path)	;~ 纠错
	Path:=a_ahkpath
	;~ MsgBox % a_ahkpath
	;}
;~ PicPath=C:\Users\Enigma\Documents\Nutstore\Games\Hearthstone\HSDisconnector\HSDisconnector.exe
;~ =================================================自运行部分
;~ MsgBox %Path%
Menu, EMenuPop, Add, 打开目录, MenuHandler	;{ -- Menu菜单
			Menu, EMenuPop, Add, 帮助, MenuHandler
			Menu, EMenuPop, Add
			Menu, EMenuPop, Add, 设置, MenuHandler
			Menu, EMenuPop, Add, 退出, MenuHandler	
			Menu, EMenuPop, Add
			loop,36
				Menu, EMenuPop, Add, % A_Index+4 . "秒", MenuHandler
			;}
Gui, Color, EEAA99 ;{ -- Gui界面
	Gui +LastFound  ; 让 GUI 窗口成为 上次找到的窗口 以用于下一行的命令.
	WinSet, TransColor, EEAA99
	Gui, -Caption -Border +Owner -Resize +LastFound -SysMenu +hwndhMain
	Gui, Add, Picture,AltSubmit Background gUIMOVE vMpic w%PicW% h-1, %Path%	
	;~ w:=PicW/2-6
	;~ Gui, Add, Text,xm+%w% ym+%w%,88
	Gui, Show, x%PicX% y%PicY%
	 ;}
if OnTop=1
	WinSet, AlwaysOnTop, %OnTop%, ahk_id %hMain%
Hotkey, IfWinActive
;~ MyHK={%MyHK%}
Hotkey, %MyHK%,HKLable
OnMessage(0x0201, "WM_LBUTTONDOWN")
return
#If MouseIsOver("ahk_class AutoHotkeyGUI") ;{ -- Gui界面
	WheelUp:: ;{ -- 放大图标
		MouseGetPos,,, Win,Control
		if (Win=hMain) {
			PicW++
			GuiControl,, MPic,*w%PicW% *h-1 %Path%
			IniWrite,%PicW%,%iniFile%.ini,PicPos,PicW
		}
	return ;}
	WheelDown:: ;{ -- 缩小图标
		MouseGetPos,,, Win,Control
		if (Win=hMain) {
			PicW--
			GuiControl,, MPic,*w%PicW% *h-1 %Path%
			IniWrite,%PicW%,%iniFile%.ini,PicPos,PicW
		}
	return  ;}
	RButton:: ;{ -- 退出菜单
		MouseGetPos,,, Win,Control
		if (Win=hMain) {
			Menu,EMenuPop,show
		}
	return ;}
	 ;}
#IfWinActive ;{ -- 全局热键
	*F9::
		IfWinActive,ahk_class SciTEWindow
		{
			send ^s
			sleep 200
		}
		ToolTip,重载
		Sleep,300
		Reload
	return
	F6::
		MsgBox 257,,重置插件大小及位置?
		IfMsgBox OK
			IniDelete,%iniFile%.ini,PicPos
			IniDelete,%iniFile%.ini,Program
		Reload
	return
	*F12::
		ToolTip,退出
		Sleep,300
		ExitApp
	return
 ;}
#IfWinActive ahk_class UnityWndClass ;{ -- 炉石界面
	*F4::	
		CmdStr=netsh advfirewall firewall set rule name=HSDisconnect new enable=yes
		Runwait %comspec% /c %CmdStr%,,hide
		WinGetPos,hMainX, hMainY,,,ahk_id %hMain%		
		tooltip,拔线, hMainX, hMainY
		Sleep,3000
		tooltip
		CmdStr=netsh advfirewall firewall set rule name=HSDisconnect new enable=no
		Runwait %comspec% /c %CmdStr%,,hide
	return ;}
MenuHandler: ;{ -- Menu菜单
	if A_ThisMenu=EMenuPop	
	{	
		if A_ThisMenuItem=打开目录
			run %A_ScriptDir%
		if A_ThisMenuItem=帮助
		{
			Gui,Help: +AlwaysOnTop ToolWindow +Owner  ; +Owner 避免显示任务栏按钮.
			txt=
			(
F4 快速拔线3秒重连
F8 / 图标双击
---拔线(默认6秒)

图标大小调整---滚轮上下
--------
F9   重载软件
F6   恢复默认
F12  退出软件

反馈--QQ:35512383
			)
		Gui, Help:Add, Text,gHelpUI, %txt%
		Gui, Help:Show, NoActivate, 帮助
		}
		if A_ThisMenuItem=设置
		{
			Gui, MyGui:Destroy
			Gui, MyGui:+Owner1 -Border +AlwaysOnTop
			;~ Gui +Disabled
			Gui, MyGui:Add, Edit,w42 Center vTickHSDis section
			Gui, MyGui:Add, UpDown, vMyUpDown Range1-15
			Gui, MyGui:Add, Text,ys+5 , 秒
			Gui, MyGui:Add, Hotkey,ys w60 vMyHK		
			Gui, MyGui:Add, Text,ys+3 x+3 , 热键
			;~ Gui,MyGui:Font,s12
			Gui, MyGui:Add, Button,ys gMyGuiGuiClose,确定
			;~ Gui, MyGui:Add, Text,ys gMyGuiGuiClose xm200 ym+8,√
			;~ Gui,MyGui:Font
			Gui, MyGui:Add, Edit,xs section w25 vQuikDis Center
			Gui, MyGui:Add, Text,ys+5 x+5,秒=F4
			Gui, MyGui:Add, Radio,h20 ys vMyRadioGroup1 Group, 单击		
			Gui, MyGui:Add, Radio,ys h20 x+1 vMyRadioGroup2, 双击
			Gui, MyGui:Add, Checkbox,ys-3 h27 x+1 vOnTop,置顶
			
			GuiControl, MyGui:,MyHK,%MyHK%
			GuiControl, MyGui:,MyUpDown,%TickHSDis%
			GuiControl, MyGui:,%MyRadioGroup%,1
			GuiControl, MyGui:,QuikDis,%QuikDis%
			GuiControl, MyGui:,OnTop,%OnTop%
			Gui, MyGui:show
		}
		IfInString A_ThisMenuItem,秒
		{
			StringReplace,Tick,A_THISMENUITEM,秒
			WinGetPos,hMainX, hMainY,,,ahk_id %hMain%		
			;~ MouseGetPos, OutputVarX, OutputVarY,,,ahk_id %hMain%		
			Tooltip, % Format("{:02d}",Tick), hMainX, hMainY
			SetTimer, Timer1, 1000
		}
		if A_ThisMenuItem=退出
		{
			gosub GuiClose
			ExitApp
		}
	}		
return ;}
Timer1: ;{ -- 定时器, 定时打开网络
	if (Tick=TickHSDis){
			CmdStr=netsh advfirewall firewall set rule name=HSDisconnect new enable=yes
			Runwait %comspec% /c %CmdStr%,,hide
		}
	WinGetPos,hMainX, hMainY,,,ahk_id %hMain%		
	if Tick--
		Tooltip, % Format("{:02d}",Tick), hMainX, hMainY
	else
	{
		SetTimer, Timer1, Off
		;~ SoundBeep, 4000, 2000
		Tooltip					
		CmdStr=netsh advfirewall firewall set rule name=HSDisconnect new enable=no
		Runwait %comspec% /c %CmdStr%,,hide
		;~ StdoutToVar_CreateProcess(CmdStr)
	}
return ;}
MyGuiGuiClose: ;{ -- 
	Gui,submit,NoHide
	GuiControlGet,MyRadioGroup1
	if OnTop=1
		WinSet, AlwaysOnTop, On, ahk_id %hMain%
	Else
		WinSet, AlwaysOnTop,Off, ahk_id %hMain%
	if MyRadioGroup1=1
	{
		IniWrite,MyRadioGroup1,%iniFile%.ini,Program,MyRadioGroup
		MyRadioGroup=MyRadioGroup1
	}
	else
	{
		IniWrite,MyRadioGroup2,%iniFile%.ini,Program,MyRadioGroup
		MyRadioGroup=MyRadioGroup2
	}	
	IniWrite,%OnTop%,%iniFile%.ini,Program,OnTop
	IniWrite,%QuikDis%,%iniFile%.ini,Program,QuikDis
	IniWrite,%MyHK%,%iniFile%.ini,Program,MyHK
	IniWrite,%TickHSDis%,%iniFile%.ini,Program,TickHSDis
	Gui, MyGui:Destroy  
return ;}
HelpUI: ;{ -- 移动帮助窗口
	PostMessage, 0xA1, 2
Return ;}
UIMOVE: ;{ -- Gui响应
	LBT:=A_TickCount
	PostMessage, 0xA1, 2 
	keywait,LButton
	if (a_GuiEvent="Normal" && A_TickCount-LBT<200) {
		WinGetPos,hMainX, hMainY,,,ahk_id %hMain%	
		if SubStr(MyRadioGroup,0)=1
		gosub HKLable
	}
	if a_GuiEvent=DoubleClick
	{
		if SubStr(MyRadioGroup,0)=2
			gosub HKLable
	}
	 else
		gosub GuiClose 
		
Return ;}
GuiClose: ;{ -- 
	WinGetPos,PicX,PicY,,,ahk_id %hMain%
	IniWrite,%PicX%,%iniFile%.ini,PicPos,PicX
	IniWrite,%PicY%,%iniFile%.ini,PicPos,PicY
	;~ IniWrite,%PicW%,%iniFile%.ini,PicPos,PicW
	;~ IniWrite,%PicH%,%iniFile%.ini,PicPos,PicH
Return ;}
WM_LBUTTONDOWN(wParam, lParam, Msg, hWnd) {
    global hMain
    MouseGetPos,,,, ClassNN
    ;~ if (hWnd = hMain) && (ClassNN = "Static1")
	;~ MsgBox 有
    if (hWnd != hMain)
        DllCall("user32.dll\PostMessage", "Ptr", hWnd, "Int", 0x00A1, "Ptr", 2, "Ptr", 0)
		
}

HKLable: ;{ -- 
	Path:=exeGetPath(Exe)
	if Path
	{		
		IniWrite,%Path%,%iniFile%.ini,Program,Path
		CmdStr=netsh advfirewall firewall show rule name="HSDisconnect"
		Str:=StdoutToVar_CreateProcess(CmdStr)
		IfInString, Str, HSDisconnect
		{					
			Tick:=TickHSDis
			Tooltip, % Format("{:02d}",Tick),hMainX, hMainY
			SetTimer, Timer1, 1000	
			;~ StdoutToVar_CreateProcess(CmdStr)	
		}
		else
		{
			CmdStr=netsh advfirewall firewall add rule name="HSDisconnect" dir=out program="%Path%" action=block enable=no
			StdoutToVar_CreateProcess(CmdStr)
		}
		;~ ToolTip("已连接!",1)
	}
	Else 
	{
		CmdStr=netsh advfirewall firewall set rule name=HSDisconnect new enable=no
		Runwait %comspec% /c %CmdStr%,,hide
		ToolTip("炉石未运行",1)
	}
Return ;}
;~ WM_LBUTTONDOWN()
;~ {
;~ PostMessage, 0xA1, 2 
;~ }
ToolTip(Text="", Time:="",X="", Y="", WhichToolTip=""){
	ToolTip ,%Text%,%X%,%Y%,%WhichToolTip%
	If Time
		{
			Time:=-Time*1000
			SetTimer,_ToolTip,%Time%
		}
return
_ToolTip:
	SetTimer,_ToolTip,%Time%
	ToolTip
return
}
MouseIsOver(WinTitle)	{
	MouseGetPos,,, Win,Control
return WinExist(WinTitle . " ahk_id " . Win)
}
exeGetPath(exe){		;~ 取得进程名, 完整路径.
	DetectHiddenWindows,On
	Process,Exist,%exe%
	if ErrorLevel>0
	{
		PID=%ErrorLevel%
		WinGet,Path,ProcessPath,ahk_pid %pid%
		return Path
	}
 }
 ; ----------------------------------------------------------------------------------------------------------------------
; Function .....: StdoutToVar_CreateProcess
; Description ..: Runs a command line program and returns its output.
; Parameters ...: sCmd      - Commandline to execute.
; ..............: sEncoding - Encoding used by the target process. Look at StrGet() for possible values.
; ..............: sDir      - Working directory.
; ..............: nExitCode - Process exit code, receive it as a byref parameter.
; Return .......: Command output as a string on success, empty string on error.
; AHK Version ..: AHK_L x32/64 Unicode/ANSI
; Author .......: Sean (http://goo.gl/o3VCO8), modified by nfl and by Cyruz
; License ......: WTFPL - http://www.wtfpl.net/txt/copying/
; Changelog ....: Feb. 20, 2007 - Sean version.
; ..............: Sep. 21, 2011 - nfl version.
; ..............: Nov. 27, 2013 - Cyruz version (code refactored and exit code).
; ..............: Mar. 09, 2014 - Removed input, doesn't seem reliable. Some code improvements.
; ..............: Mar. 16, 2014 - Added encoding parameter as pointed out by lexikos.
; ..............: Jun. 02, 2014 - Corrected exit code error.
; ..............: Nov. 02, 2016 - Fixed blocking behavior due to ReadFile thanks to PeekNamedPipe.
; ----------------------------------------------------------------------------------------------------------------------
StdoutToVar_CreateProcess(sCmd, sEncoding:="CP0", sDir:="", ByRef nExitCode:=0) {
    DllCall( "CreatePipe",           PtrP,hStdOutRd, PtrP,hStdOutWr, Ptr,0, UInt,0 )
    DllCall( "SetHandleInformation", Ptr,hStdOutWr, UInt,1, UInt,1                 )

            VarSetCapacity( pi, (A_PtrSize == 4) ? 16 : 24,  0 )
    siSz := VarSetCapacity( si, (A_PtrSize == 4) ? 68 : 104, 0 )
    NumPut( siSz,      si,  0,                          "UInt" )
    NumPut( 0x100,     si,  (A_PtrSize == 4) ? 44 : 60, "UInt" )
    NumPut( hStdOutWr, si,  (A_PtrSize == 4) ? 60 : 88, "Ptr"  )
    NumPut( hStdOutWr, si,  (A_PtrSize == 4) ? 64 : 96, "Ptr"  )

    If ( !DllCall( "CreateProcess", Ptr,0, Ptr,&sCmd, Ptr,0, Ptr,0, Int,True, UInt,0x08000000
                                  , Ptr,0, Ptr,sDir?&sDir:0, Ptr,&si, Ptr,&pi ) )
        Return ""
      , DllCall( "CloseHandle", Ptr,hStdOutWr )
      , DllCall( "CloseHandle", Ptr,hStdOutRd )

    DllCall( "CloseHandle", Ptr,hStdOutWr ) ; The write pipe must be closed before reading the stdout.
    While ( 1 )
    { ; Before reading, we check if the pipe has been written to, so we avoid freezings.
        If ( !DllCall( "PeekNamedPipe", Ptr,hStdOutRd, Ptr,0, UInt,0, Ptr,0, UIntP,nTot, Ptr,0 ) )
            Break
        If ( !nTot )
        { ; If the pipe buffer is empty, sleep and continue checking.
            Sleep, 100
            Continue
        } ; Pipe buffer is not empty, so we can read it.
        VarSetCapacity(sTemp, nTot+1)
        DllCall( "ReadFile", Ptr,hStdOutRd, Ptr,&sTemp, UInt,nTot, PtrP,nSize, Ptr,0 )
        sOutput .= StrGet(&sTemp, nSize, sEncoding)
    }
    
    ; * SKAN has managed the exit code through SetLastError.
    DllCall( "GetExitCodeProcess", Ptr,NumGet(pi,0), UIntP,nExitCode )
    DllCall( "CloseHandle",        Ptr,NumGet(pi,0)                  )
    DllCall( "CloseHandle",        Ptr,NumGet(pi,A_PtrSize)          )
    DllCall( "CloseHandle",        Ptr,hStdOutRd                     )
    Return sOutput
}

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

GUI设置热键的例子

2021-12-2 15:23:16

其他

install

2021-12-2 15:23:29

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索