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 删除指定的自定义扫描代码组合。 键盘筛选器停止阻止已删除的扫描代码组合。

属性

属性 数据类型 限定符 说明
修饰符 字符串 [key] 作为要阻止的组合键的一部分的修改键。
Scancode uint16 [key] 要阻止的组合键的扫描代码部分。
已启用 Boolean [read, write] 指示是阻止还是取消阻止扫描代码。 此属性可以是以下值之一:
- true 指示扫描代码被阻止。
- 指示扫描代码未被阻止。

注解

当按下某个键时,将由键盘生成扫描代码。 无论系统当前使用哪种键盘布局,相同的物理密钥都将始终生成相同的扫描代码。

可以通过在 Add 方法的修饰符参数中包含修改键或修改修饰符属性来指定组合键。 最常见的修改键名称有“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 专业版
Windows 企业版
Windows 教育版
Windows IoT 企业版 是的

键盘筛选器 WMI 提供程序参考

键盘筛选器