如何将活动窗口与窗口数组中的窗口列表进行测试?

huangapple go评论51阅读模式
英文:

How to test the active window against a list of windows in an array?

问题

I can help with the translation. Here's the translated content:

我正在尝试编写一个简单的程序来解决我在使用Ctrl+C时遇到的不一致行为。在某些程序中,比如VSCode,即使没有活动选择,Ctrl+C也会复制文本到剪贴板。

VSCode提供了一种禁用此功能的方法,但我的一些编辑器却没有,比如Windows终端。

我想要实现的目标是,如果其中一个“高级编辑器”处于活动状态,然后发送Ctrl+X。否则发送Ctrl+C。我卡在了如何测试活动程序与我心中所想的程序列表之间的关系。

~space::
AdvancedEditors := ["ahk_exe WindowsTerminal.exe", "ahk_exe Code.exe"]
; BasicEditors  : = ["ahk_exe Notepad.exe"]  

ThisKey := (If WinActive(AdvancedEditors)) ? "x" : "c"
SendInput, ^{%ThisKey%}

我尝试过使用GroupAdd命令,但是我无法弄清楚它。更重要的是,我非常渴望学习如何使用上面的格式来实现这一点。这是否可能?

非常感谢!

英文:

I am trying to write a simple program to solve the inconsistent behaviours I am getting with Ctrl+C. In some programs, such as VSCode, Ctrl+C copies text to clipboard, even if there is not a active selection.

VSCode offers a means to disable this, but some of my editors do not, such as Windows Terminal

The goal I have in mind is, if one of these "Advanced Editors" is active then send, Ctrl+X. Otherwise send Ctrl+C. I am stuck on testing the active program against a list of programs I have in mind

~space::
AdvancedEditors := ["ahk_exe WindowsTerminal.exe", "ahk_exe Code.exe"]
; BasicEditors  : = ["ahk_exe Notepad.exe"]  

ThisKey := (If WinActive(AdvancedEditors)) ? "x": "c"
SendInput, ^{%Thiskey%}

I tried experimenting with the GroupAdd command but I could not figure out it. More importantly, I am really keen on learning how I can do this with an array, in the above format. Is that possible?

Thanks allot

答案1

得分: 2

GroupAdd更简单,程序不需要每次发送^c时循环遍历数组。

; 自动执行部分:

#NoEnv
#SingleInstance Force

GroupAdd, AdvancedEditors, ahk_exe WindowsTerminal.exe
GroupAdd, AdvancedEditors, ahk_exe Code.exe

; ...

RETURN ; === 自动执行部分的结尾 ===

#IfWinActive ahk_group AdvancedEditors

^c::^x

#IfWinActive

英文:

GroupAdd is simpler and the program does not need to loop through the array each time ^c is sent.

; auto-execute section:

#NoEnv
#SingleInstance Force

GroupAdd, AdvancedEditors, ahk_exe WindowsTerminal.exe
GroupAdd, AdvancedEditors, ahk_exe Code.exe

; ...

			RETURN	 ; === end of auto-execute section ===


#IfWinActive ahk_group AdvancedEditors

	^c::^x
	
#IfWinActive

huangapple
  • 本文由 发表于 2023年5月14日 06:46:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245168.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定