WEKF_Scancode

キーが押されたり離されたりするたびに生成される整数であるキーボード スキャン コードを使用して、キーの組み合わせをブロックまたはブロック解除します。

構文

class WEKF_Scancode {
    [Static] uint32 Add(
        [In] string Modifiers,
        [In] uint16 scancode
    );
    [Static] uint32 Remove(
        [In] string Modifiers,
        [In] uint16 Scancode
    );

    [Key] string Modifiers;
    [Key] uint16 Scancode;
    [Read, Write] boolean Enabled;
}

メンバー

次の表に、このクラスに属するコンストラクター、メソッド、フィールド、およびプロパティを示します。

メソッド

メソッド 説明
WEKF_Scancode.Add 新しいカスタム スキャン コードの組み合わせを追加し、キーボード フィルターを有効にして、新しいスキャン コードの組み合わせをブロックします。
WEKF_Scancode.Remove 指定したカスタム スキャン コードの組み合わせを削除します。 削除されたスキャン コードの組み合わせは、キーボード フィルターでブロックされなくなります。

Properties

プロパティ データ型 修飾子 説明
修飾子 string [key] ブロックするキーの組み合わせに含まれる修飾キー。
Scancode uint16 [key] ブロックするキーの組み合わせに含まれるスキャン コード。
有効 Boolean [read, write] スキャン コードがブロックされているか、ブロック解除されているかを示します。 このプロパティには、次のいずれかの値を指定できます:
- true スキャン コードがブロックされていることを示します。
- False スキャン コードがブロックされていないことを示します。

注釈

スキャン コードは、キーが押されるたびにキーボードによって生成されます。 システムで現在使用されているキーボード レイアウトに関係なく、同じ物理キーからは常に同じスキャン コードが生成されます。

キーの組み合わせを指定するには、Add メソッドの Modifiers パラメーターに修飾子キーを含めるか、Modifiers プロパティを変更します。 最も一般的な修飾子名は、"Ctrl"、"Shift"、"Alt"、および "Win" です。

次のコードは、キーボード フィルター用の Windows Management Instrumentation (WMI) プロバイダーを使用して、キーボード フィルターがブロックするキーボード スキャン コードを追加または有効にする方法を示しています。 この例では、プロパティを直接変更し、WEKF_Scancode で定義されているどのメソッドも呼び出しません。

<#
.Synopsis
    This script shows how to use the WMI provider to enable and add 
    Keyboard Filter rules through Windows Powershell on the local computer.
.Parameter ComputerName
    Optional parameter to specify a remote machine 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 Enable-Scancode($Modifiers, [int]$Code) {
    <#
    .Synopsis
        Toggle on a Scancode Keyboard Filter Rule
    .Description
        Use Get-WMIObject to enumerate all WEKF_Scancode instances,
        filter against key values of "Modifiers" and "Scancode", and set
        that instance's "Enabled" property to 1/true.

        In the case that the Scancode instance does not exist, add a new
        instance of WEKF_Scancode using Set-WMIInstance.
    .Example
        Enable-Predefined-Key "Ctrl+V"

        Enable filtering of the Ctrl + V sequence.
#>

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

    if($scancode) {
        $scancode.Enabled = 1
        $scancode.Put() | Out-Null
        "Enabled Custom Scancode {0}+{1:X4}" -f $Modifiers, $Code
    } else {
        Set-WMIInstance `
            -class WEKF_Scancode `
            -argument @{Modifiers="$Modifiers"; Scancode=$Code} `
            @CommonParams | Out-Null
 
        "Added Custom Scancode {0}+{1:X4}" -f $Modifiers, $Code
    }
}

# Some example uses of the function defined above.

Enable-Scancode "Ctrl" 37

要件

Windows エディション サポートされています
Windows ホーム いいえ
Windows Pro いいえ
Windows Enterprise はい
Windows Education はい
Windows IoT Enterprise はい

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

キーボード フィルター