WEKF_CustomKey

添加或删除自定义组合键。

语法

class WEKF_CustomKey {
    [Static] uint32 Add(
        [In] string CustomKey
    );
    [Static] uint32 Remove(
        [In] string CustomKey
    );

    [Key] string Id;
    [Read, Write] boolean Enabled;
};

成员

下表列出了属于此类的任何方法和属性。

方法

方法 说明
WEKF_CustomKey.Add 创建新的自定义组合键,并启用键盘筛选器来阻止新的组合键。
WEKF_CustomKey.Remove 删除指定的自定义组合键。 键盘筛选器停止阻止已删除的组合键。

属性

属性 数据类型 限定符 说明
Id string [key] 自定义组合键的名称。
已启用 Boolean [read, write] 指示是阻止还是取消阻止键。 此属性可以是以下值
- 之一 true 指示密钥被阻止。
- 指示密钥未阻止。

注解

可以通过在名称中包含修改键来指定组合键。 最常见的修改键名称有“Ctrl”、“Shift”、“Alt”和“Win”。 不能阻止非修改键的组合。 例如,可以阻止“Ctrl+Shift+F”的组合键,但不能阻止“A+D”的组合键。

阻止 Shift 修改键时,必须输入“Shift”+ 未修改键。 例如,若要阻止英语键盘布局上的 % 键,必须将键指定为“Shift+5”。 尝试阻止“%”会导致键盘筛选器错误地阻止“5”。

指定要阻止的组合键时,必须使用键的英语名称。 有关可以指定的键名称的列表,请参阅键盘筛选器键名称。

示例

以下代码演示了如何使用键盘筛选器的 Windows Management Instrumentation (WMI) 提供程序来添加或启用键盘筛选器将阻止的自定组合键。 此示例直接修改属性,不调用在 WEKF_CustomKey 中定义的任何方法。

<#
.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-Custom-Key($Id) {
    <#
    .Synopsis
        Toggle on a Custom Key Keyboard Filter Rule
    .Description
        Use Get-WMIObject to enumerate all WEKF_CustomKey instances,
        filter against key value "Id", and set that instance's "Enabled"
        property to 1/true.

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

        Enable filtering of the Ctrl + V sequence.
#>

    $custom = Get-WMIObject -class WEKF_CustomKey @CommonParams |
        where {
            $_.Id -eq "$Id"
        };

    if ($custom) {
# Rule exists.  Just enable it.
        $custom.Enabled = 1;
        $custom.Put() | Out-Null;
        "Enabled Custom Filter $Id.";

    } else {
        Set-WMIInstance `
            -class WEKF_CustomKey `
            -argument @{Id="$Id"} `
            @CommonParams | Out-Null

        "Added Custom Filter $Id.";
    }
}


# Some example uses of the function defined above.

Enable-Custom-Key "Ctrl+V"
Enable-Custom-Key "Numpad0"
Enable-Custom-Key "Shift+Numpad1"

要求

Windows 版本 支持
Windows 主页
Windows 专业版
Windows 企业版
Windows 教育版
Windows IoT 企业版 是的

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

键盘筛选器键名