次の方法で共有


WEKF_Scancode

サポートされているエディション
✅ IoT Enterprise LTSC
✅ IoT Enterprise
✅ Enterprise LTSC
✅ Enterprise
✅ Education

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

構文

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;
}

Members

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

メソッド

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

プロパティ

プロパティ データ型 修飾子 説明
修飾子 文字列 [キー] ブロックするキーの組み合わせの一部である修飾子キー。
Scancode uint16 [キー] ブロックするキーの組み合わせのスキャン コード部分。
Enabled ブール値 [読み取り、書き込み] スキャン コードがブロックされているかブロック解除されているかを示します。 このプロパティには、次のいずれかの値を指定できます:
- true スキャン コードがブロックされていることを示します
- スキャン コードがブロックされていないことを示します。

注釈

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

キーの組み合わせを指定するには、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

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

キーボード フィルター