キーの組み合わせ構成の削除

次のサンプル Windows PowerShell スクリプトでは、キーボードフィルター用の Windows Management Instrumentation (WMI) プロバイダーを使用して、キーボード フィルターからカスタム定義のキーの組み合わせ構成を削除する 2 つの関数を作成します。 各関数を使用する複数の方法を示します。

最初の関数 Remove-Custom-Key は、カスタム キーの組み合わせ構成を削除します。

2 番目の関数 Remove-Scancode は、カスタム スキャン コード構成を削除します。

キーボード フィルターの定義済みのキーの組み合わせ構成を削除することはできませんが、無効にすることはできます。

Remove-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 script samples for keyboard filter

キーボード フィルター WMI プロバイダー リファレンス

キーボード フィルター