Autoit死循环问题

发布于 2024-10-23 19:18:11 字数 1431 浏览 0 评论 0原文

在 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

In SSMS (SQL Server Management Studio), you have to middle-click the tab or press Ctrl+F4 to close the current editor tab. I want to use Autoit to make a shortcut Ctrl+w do the same thing. But I have problem with it. The following is the code. What I thought is, when the user press Ctrl+w, check if the user is in SSMS, if so, send Ctrl+F4 to close the current tab, if not, send Ctrl+w to let it go as normal. But the point is, if you send Ctrl+w, it will be captured again by Autoit, so dead loop occurs. I can't find a way to solve this problem. Anyone can help me with it?

Thanks.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲影 2024-10-30 19:18:11

我找到了解决方案。

; 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

I found the solution.

; 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文