2011-03-21 90 views
1

在SSMS(SQL Server Management Studio)中,您必須中鍵單擊該選項卡或按Ctrl + F4才能關閉當前編輯器選項卡。我想用Autoit來做一個快捷方式Ctrl + w做同樣的事情。但我有問題。以下是代碼。我認爲,用戶按時按Ctrl瓦特,檢查,如果用戶在SSMS如果是這樣,發送按Ctrl + F4關閉當前標籤頁,如果沒有,發送按Ctrl + w讓它照常進行。但重點是,如果您發送Ctrl + w,它將被Autoit再次捕獲,因此發生死循環。我找不到解決這個問題的方法。任何人都可以幫助我嗎?Autoit死循環問題

謝謝。

HotKeySet("^w", "close_ssms_editor") 

While 1 
    Sleep(200) 
WEnd 

; using Ctrl + w to close 
; * editors in SSMS 
; * editors in SSMS through Royal TS 
Func close_ssms_editor() 
    $window_class_name = get_window_class_name(WinGetHandle("")) 
    If $window_class_name = "wndclass_desked_gsk" or $window_class_name = "WindowsForms10.Window.8.app.0.218f99c" Then 
     Send("^{F4}") 
    Else 
     Send("^w") 
    EndIf 
EndFunc 


Func get_window_class_name($nCtrl) 
    If Not IsHWnd($nCtrl) then $nCtrl = HWnd($nCtrl) 
    Local $struct = DllStructCreate("char[128]"),$classname = 0 
    $ret = DllCall("user32.dll","int","GetClassName","hwnd",$nCtrl,"ptr",DllStructGetPtr($struct),"int",DllStructGetSize($struct)) 
    If IsArray($ret) Then 
     $classname = DllStructGetData($struct,1) 
     While (StringIsDigit(StringRight($classname,1))) 
      $classname = StringTrimRight($classname,1) 
     WEnd 
    EndIf 
    $struct =0 
    Return $classname 
EndFunc 

回答

1

我找到了解決方案。

; using Ctrl + w to close 
; * editor in SSMS 
; * editor in SSMS through Royal TS 
Func close_ssms_editor() 
    $window_class_name = get_window_class_name(WinGetHandle("")) 
    If $window_class_name = "wndclass_desked_gsk" or $window_class_name = "WindowsForms10.Window.8.app.0.218f99c" Then 
     Send("^{F4}") 
    Else 
     HotKeySet("^w") 
     Send("^w") 
     HotKeySet("^w", "close_ssms_editor") 
    EndIf 
EndFunc