Windows 11中PowerShell ISE查找对话框回车失效问题求助
解决Windows 11中PowerShell ISE查找对话框回车无效问题
方案1:兼容性模式运行PowerShell ISE
- 定位到
C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe - 右键点击文件 → 「属性」→ 「兼容性」标签
- 勾选「以兼容模式运行这个程序」,选择「Windows 10」
- 点击「应用」「确定」后重启PowerShell ISE
方案2:用脚本自动设置「Find Next」为默认按钮
运行以下PowerShell脚本,它会自动监听查找对话框的显示事件,将「Find Next」设为默认按钮,之后回车即可触发搜索:
Add-Type @" using System; using System.Runtime.InteropServices; using System.Windows.Forms; public class ISEFixer { [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll")] private static extern bool SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); private const uint BM_SETDEFAULT = 0x00F7; public static void SetFindNextAsDefault() { IntPtr findDialog = FindWindow("#32770", "Find"); if (findDialog != IntPtr.Zero) { IntPtr button = FindWindowEx(findDialog, IntPtr.Zero, "Button", "&Find Next"); if (button != IntPtr.Zero) { SendMessage(button, BM_SETDEFAULT, IntPtr.One, IntPtr.Zero); } } } } "@ # 绑定到查找对话框显示事件 Register-ObjectEvent -InputObject $psISE.CurrentPowerShellTab.VerticalAddOnTools['Find'] -EventName VisibleChanged -Action { [ISEFixer]::SetFindNextAsDefault() }
如果希望每次启动ISE自动加载这个脚本,把上述代码添加到你的PowerShell配置文件中(运行notepad $PROFILE打开配置文件,粘贴后保存即可)。
方案3:临时替代快捷键
在查找对话框中输入关键词后,尝试按下Ctrl+Enter,部分场景下可以直接触发搜索,无需切换按钮焦点。
内容的提问来源于stack exchange,提问作者skataben
相关产品推荐
相关产品推荐

