移除按鍵組合的組態Remove key combination configurations

下列範例 Windows PowerShell 指令碼會使用鍵盤篩選器的 Windows Management Instrumentation (WMI) 提供者來建立兩個函式,從鍵盤的篩選條件移除組合鍵進行自訂的設定。The following sample Windows PowerShell script uses the Windows Management Instrumentation (WMI) providers for Keyboard Filter to create two functions to remove custom-defined key combination configurations from Keyboard Filter. 它會示範數種方式可使用每個函式。It demonstrates several ways to use each function.

第一個函式中,移除自訂金鑰,移除自訂的按鍵組合的組態。The first function, Remove-Custom-Key, removes custom key combination configurations.

第二個函式中,移除 Scancode,移除自訂掃描程式碼設定。The second function, Remove-Scancode, removes custom scan code configurations.

您無法移除鍵盤篩選的預先定義的按鍵組合設定,但您可以停用它們。You cannot remove the predefined key combination configurations for Keyboard Filter, but you can disable them.

Remove-rules.ps1Remove-rules.ps1

#
# Copyright (C) Microsoft. All rights reserved.
#

<#
.Synopsis
    This script shows how to use the build in WMI providers to remove keyboard filter rules.  Rules of type WEKF_PredefinedKey cannot be removed.
.Parameter ComputerName
    Optional parameter to specify the remote computer that this script should
    manage.  If not specified, the script will execute all WMI operations
    locally.
#>

param(
    [string] $ComputerName
)

$CommonParams = @{"namespace"="root\standardcimv2\embedded"}
$CommonParams += $PSBoundParameters

function Remove-Custom-Key($Id) {
    <#
    .Synopsis
        Remove an instance of WEKF_CustomKey
    .Description
        Enumerate all instances of WEKF_CustomKey.  When an instance has an
        Id that matches $Id, delete it.
    .Example
        Remove-Custom-Key "Ctrl+V"

        This removes the instance of WEKF_CustomKey with a key Id of "Ctrl+V"
#>

    $customInstance = Get-WMIObject -class WEKF_CustomKey @CommonParams |
        where {$_.Id -eq $Id}

    if ($customInstance) {
        $customInstance.Delete();
        "Removed Custom Filter $Id.";
    } else {
        "Custom Filter $Id does not exist.";
    }
}

function Remove-Scancode($Modifiers, [int]$Code) {
    <#
    .Synopsis
        Remove and instance of WEKF_Scancode
    .Description
        Enumerate all instances of WEKF_Scancode.  When an instance has a
        matching modifiers and code, delete it.
    .Example
        Remove-Scancode "Ctrl" 37

        This removes the instance of WEKF_Scancode with Modifiers="Ctrl" and
        Scancode=37.
#>

    $scancodeInstance = Get-WMIObject -class WEKF_Scancode @CommonParams |
        where {($_.Modifiers -eq $Modifiers) -and ($_.Scancode -eq $Code)}

    if ($scancodeInstance) {
        $scancodeInstance.Delete();
        "Removed Scancode $Modifiers+$Code.";
    } else {
        "Scancode $Modifiers+$Code does not exist.";
    }
}

# Some example uses of the functions defined above.
Remove-Custom-Key "Ctrl+V"
Remove-Custom-Key "Numpad0"
Remove-Custom-Key "Shift+Numpad1"
Remove-Custom-Key "%"
Remove-Scancode "Ctrl" 37

鍵盤篩選器的 Windows PowerShell 指令碼範例Windows PowerShell script samples for keyboard filter

鍵盤篩選 WMI 提供者參考資料Keyboard filter WMI provider reference

鍵盤篩選Keyboard filter