WEKF_Scancode

Blocks or unblocks key combinations by using the keyboard scan code, which is an integer number that is generated whenever a key is pressed or released.

Syntax

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

The following tables list any constructors, methods, fields, and properties that belong to this class.

Methods

Methods Description
WEKF_Scancode.Add Adds a new custom scan code combination and enables Keyboard Filter to block the new scan code combination.
WEKF_Scancode.Remove Removes the specified custom scan code combination. Keyboard Filter stops blocking the scan code combination that was removed.

Properties

Property Data type Qualifiers Description
Modifiers string [key] The modifier keys that are part of the key combination to block.
Scancode uint16 [key] The scan code part of the key combination to block.
Enabled Boolean [read, write] Indicates whether the scan code is blocked or unblocked. This property can be one of the following values:
- true Indicates that the scan code is blocked.
- false Indicates that the scan code is not blocked.

Remarks

Scan codes are generated by the keyboard whenever a key is pressed. The same physical key will always generate the same scan code, regardless of which keyboard layout is currently being used by the system.

You can specify key combinations by including the modifier keys in the Modifiers parameter of the Add method or by modifying the Modifiers property. The most common modifier names are “Ctrl”, “Shift”, “Alt”, and “Win”.

Example

The following code demonstrates how to add or enable a keyboard scan code that Keyboard Filter will block by using the Windows Management Instrumentation (WMI) providers for Keyboard Filter. This example modifies the properties directly, and does not call any of the methods defined in 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

Requirements

Windows Edition Supported
Windows Home No
Windows Pro No
Windows Enterprise Yes
Windows Education Yes
Windows IoT Enterprise Yes

Keyboard Filter WMI provider reference

Keyboard Filter