WEKF_CustomKey.Add

创建新的自定义组合键,并启用键盘筛选器来阻止新的组合键。

语法

[Static] uint32 Add(
    [In] string CustomKey
);

参数

CustomKey
[in]要添加的自定义组合键。 如需有效键名称的列表,请参阅键盘筛选器键名称

返回值

返回指示 WMI 非错误常量WMI 错误常量的 HRESULT 值。

注解

WEKF_CustomKey.Add 会创建一个新的 WEKF_CustomKey 对象,并将新对象的的 Enabled 属性设置为 true,将 Id 属性设置为 CustomKey。

如果 WEKF_CustomKey 对象已存在,并且 Id 属性等于 CustomKey,则 WEKF_CustomKey.Add 将返回错误代码,并且不会创建新对象或修改现有对象的任何属性。 如果现有 WEKF_CustomKey 对象将 Enabled 属性设置为 false,则键盘筛选器不会阻止自定义组合键。

示例

以下代码演示了如何使用键盘筛选器的 Windows Management Instrumentation (WMI) 提供程序来添加或启用键盘筛选器将阻止的自定义键。

$COMPUTER = "localhost"
$NAMESPACE = "root\standardcimv2\embedded"

# Create a handle to the class instance so we can call the static methods
$classCustomKey = [wmiclass]"\\$COMPUTER\${NAMESPACE}:WEKF_CustomKey"

# Create a function to add or enable a key combination for Keyboard Filter to block
function Enable-Custom-Key($KeyId) {

# Check to see if the custom key object already exists
    $objCustomKey = Get-WMIObject -namespace $NAMESPACE -class WEKF_CustomKey |
            where {$_.Id -eq "$KeyId"};

    if ($objCustomKey) {

# The custom key already exists, so just enable it
        $objCustomKey.Enabled = 1;
        $objCustomKey.Put() | Out-Null;
        "Enabled ${KeyId}.";

    } else {

# Create a new custom key object by calling the static Add method
        $retval = $classCustomKey.Add($KeyId);

# Check the return value to verify that the Add is successful
        if ($retval.ReturnValue -eq 0) {
            "Added ${KeyID}."
        } else {
            "Unknown Error: " + "{0:x0}" -f $retval.ReturnValue
        }
    }
}

# Enable Keyboard Filter to block several custom keys

Enable-Custom-Key "Ctrl+v"
Enable-Custom-Key "Ctrl+v"
Enable-Custom-Key "Shift+4"
Enable-Custom-Key "Ctrl+Alt+w"

# List all the currently existing custom keys

$objCustomKeyList = get-WMIObject -namespace $NAMESPACE -class WEKF_CustomKey
foreach ($objCustomKeyItem in $objCustomKeyList) {
    "Custom key: " + $objCustomKeyItem.Id
    "   enabled: " + $objCustomKeyItem.Enabled
    }

要求

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