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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。
I found the solution.