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

MembersMembers

下表列出了属于此类的任何构造函数、方法、字段和属性。The following tables list any constructors, methods, fields, and properties that belong to this class.

方法Methods

方法Methods 说明Description

WEKF_Scancode.AddWEKF_Scancode.Add

添加新的自定义扫描代码组合,并允许键盘筛选器阻止新的扫描代码组合。Adds a new custom scan code combination and enables Keyboard Filter to block the new scan code combination.

WEKF_Scancode.RemoveWEKF_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

stringstring

按键[key]

作为要阻止的键组合的一部分的修饰符键。The modifier keys that are part of the key combination to block.

ScancodeScancode

uint16uint16

按键[key]

要阻止的键组合的扫描代码部分。The scan code part of the key combination to block.

EnabledEnabled

布尔Boolean

[读取、写入][read, write]

指示扫描代码是否被阻止或取消阻止。Indicates whether the scan code is blocked or unblocked. 此属性可以是以下值之一:This property can be one of the following values:

Value 说明Description

truetrue

指示扫描代码被阻止。Indicates that the scan code is blocked.

falsefalse

指示扫描代码未被阻止。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.

可以通过在Add方法的修饰符参数中包含修改键或修改修饰符属性来指定键组合。You can specify key combinations by including the modifier keys in the Modifiers parameter of the Add method or by modifying the Modifiers property. 最常见的修改名称为 "Ctrl"、"Shift"、"Alt" 和 "Win"。The most common modifier names are “Ctrl”, “Shift”, “Alt”, and “Win”.

示例Example

下面的代码演示如何通过使用适用于键盘筛选器的 Windows Management Instrumentation (WMI)提供程序来添加或启用键盘筛选器将阻止的键盘扫描代码。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. 此示例直接修改属性,不会调用WEKF_Scancode中定义的任何方法。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 版本Windows Edition 支持Supported
Windows 10 家庭版Windows 10 Home No
Windows 10 专业版Windows 10 Pro No
Windows 10 企业版Windows 10 Enterprise Yes
Windows 10 教育版Windows 10 Education Yes

键盘筛选器 WMI 提供程序参考Keyboard Filter WMI provider reference

键盘筛选器Keyboard Filter