自动死循环问题

时间:2011-03-21 03:36:03

标签: deadlock ssms autoit

在SSMS(SQL Server Management Studio)中,您必须在中间单击选项卡或按 Ctrl + F4 以关闭当前编辑器选项卡。我想用Autoit来创建一个快捷方式 Ctrl + w 做同样的事情。但我有问题。以下是代码。我的想法是,当用户按 Ctrl + w 时,检查用户是否在SSMS,如果是,请发送 Ctrl + F4 关闭当前标签,如果没有,发送 Ctrl + w 让它正常运行。但关键是,如果发送 Ctrl + w ,它将被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 个答案:

答案 0 :(得分: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