windows - Powershell,关闭活动窗口
问题描述
我找到了一个我修改的片段以找到活动窗口并通过 ps1 脚本将其关闭。我的目标是使用 hotkeyD 使我的键绑定与 Linux 相同。
我的脚本有三个问题。一个是如果我正在浏览文件,它不会关闭活动的资源管理器窗口。我将如何做到这一点?
第二个问题是。我希望 winfetch 一启动就在终端中执行。但是,如果我将它添加到我的 powershell 配置文件中。它使脚本需要更长的时间来执行。如何使脚本省略我在文档中的 powershell 配置文件中的代码?
三是速度。脚本不是即时的。就像按 alt+F4 一样。它需要一两秒钟才能激活。我将如何加快速度?
谢谢。期待看到一些回复。这是脚本。
[CmdletBinding()]
Param(
)
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class UserWindows {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
try {
$ActiveHandle = [UserWindows]::GetForegroundWindow()
$Process = Get-Process | ? {$_.MainWindowHandle -eq $activeHandle}
$Process | Select ProcessName, @{Name="AppTitle";Expression= {($_.CloseMainWindow())}}
} catch {
Write-Error "Failed to get active Window details. More Info: $_"
}
exit
解决方案
这种类型的任务(即创建一个关闭活动窗口的热键)看起来比 Powershell更适合AutoHotkey 。
例如,这可以在 AutoHotkey 中使用:
#d::WinClose A ;remaps Super+d to a "close the Active Window" command
如果您想了解有关如何设置AHK
或此脚本特别是如何工作的更多信息,请随时 lmk。
推荐阅读
- java - Java猜数字游戏
- autodesk-forge - 在 ForgeViewer 中使剖切面与自定义网格一起工作
- c# - 进程(CMD)未关闭,因此无法启动新进程
- reactjs - React Redux 状态未更新
- firebase - 如何避免函数调用深度限制?
- spring-boot - Cloud Foundry 上的 Spring Boot 管理服务器和 SimpleDiscoveryClient
- c# - .NET Core 如何以独立于操作系统的方式获取所有时区 + 信息
- c# - 如何在 WPF C# 中更改滑块上刻度的设计(刻度的厚度、刻度的形状等)
- bash - 用bash中的变量更新全局变量的值
- apache-camel - Apache骆驼如何为窃听器实现可选的消费者