1

在 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
4

1 回答 1

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
于 2011-03-21T04:42:31.047 回答