wpf - WPF 和 Powershell 的键盘快捷键

标签 wpf powershell keyboard-shortcuts

在下面的代码中:

Add-Type -AssemblyName PresentationFramework
$window = New-Object Windows.Window
$commonKeyEvents = {
    [System.Windows.Input.KeyEventArgs] $e = $args[1]
    if ($e.Key -eq 'ESC') { $this.close() }
    if ($e.Key -eq 'Ctrl+Q') { $this.close() }
}
$window.add_PreViewKeyDown($commonKeyEvents)
$window.ShowDialog() | Out-Null

'Ctrl+Q' 部分不起作用。我怎么能让这个工作?

最佳答案

给你:

Add-Type -AssemblyName PresentationFramework
$window = New-Object Windows.Window

$commonKeyEvents = {
    [System.Windows.Input.KeyEventArgs] $e = $args[1]

    if (($e.Key -eq "Q" -and $e.KeyboardDevice.Modifiers -eq "Ctrl") -or
        ($e.Key -eq "ESC")) {            
        $this.Close()
    }
}

$window.Add_PreViewKeyDown($commonKeyEvents)
$window.ShowDialog() | Out-Null

更简单:

Add-Type -AssemblyName PresentationFramework
$window = New-Object Windows.Window

$commonKeyEvents = {
    if (($_.Key -eq "Q" -and $_.KeyboardDevice.Modifiers -eq "Ctrl") -or
        ($_.Key -eq "ESC")) {            
        $this.Close()
    }
}

$window.Add_PreViewKeyDown($commonKeyEvents)
$window.ShowDialog() | Out-Null

关于wpf - WPF 和 Powershell 的键盘快捷键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50514701/

相关文章:

xcode - 更改 XCode 4 多点触控手势

.net - 在 TextBlock 内对齐 TextBox

c# - 删除的 zip 文件会导致 e.Data.GetData ("FileContents") 引发异常

powershell - 使用 Powershell 替换方括号

json - 为什么此字符串不在 PowerShell 中序列化为简单的 JSON 字符串

macos - Android Studio : Extract method shortcut '⌥+⌘+M' (Option-Command-M) no longer working (macOS Mojave)

c# - 以 Windows XP 为目标平台的 VS 2015 中推荐的内容

wpf - 使用 WindowsformsHost 将报表查看器插入 WPF 应用程序时出现问题

.net - Get-ChildItem 与直接使用具有 UNC 路径的 .NET Framework 的 [System.IO.Directory]::GetFiles() 方法

Eclipse 多个键盘快捷键