WEKF _ CustomKeyWEKF_CustomKey.Add

创建新的自定义组合键,并启用键盘筛选器以阻止新的键组合。Creates a new custom key combination and enables Keyboard Filter to block the new key combination.

语法Syntax

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

参数Parameters

CustomKeyCustomKey
[]要添加的自定义键组合。[in] The custom key combination to add. 有关有效密钥名称的列表,请参阅 键盘筛选器密钥名称For a list of valid key names, see Keyboard Filter key names.

返回值Return Value

返回一个 HRESULT 值,该值指示 Wmi 非错误常量wmi 错误常量Returns an HRESULT value that indicates a WMI Non-Error Constant or a WMI Error Constant.

备注Remarks

WEKF _CustomKey 创建新的 WEKF _ CustomKey 对象,并将新对象的 Enabled 属性设置为 true ,并将 Id 属性设置为 CustomKeyWEKF_CustomKey.Add creates a new WEKF_CustomKey object and sets the Enabled property of the new object to true , and the Id property to CustomKey.

如果 WEKF _ CustomKey 对象已存在,并且 Id 属性等于 CustomKey ,则 WEKF _ CustomKey 将 返回错误代码,并且不会创建新的对象或修改现有对象的任何属性。If a WEKF_CustomKey object already exists with the Id property equal to CustomKey , then WEKF_CustomKey.Add returns an error code and does not create a new object or modify any properties of the existing object. 如果现有的 WEKF _ CustomKey 对象将 Enabled 属性设置为 false ,则键盘筛选器不会阻止自定义键组合。If the existing WEKF_CustomKey object has the Enabled property set to false , Keyboard Filter does not block the custom key combination.

示例Example

下面的代码演示如何通过使用 Windows Management Instrumentation (WMI) 提供程序(用于键盘筛选器)来添加或启用键盘筛选器将阻止的自定义键。The following code demonstrates how to add or enable a custom key that Keyboard Filter will block by using the Windows Management Instrumentation (WMI) providers for Keyboard Filter.

$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
    }

要求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

WEKF _ CustomKeyWEKF_CustomKey

键盘筛选器Keyboard Filter