WEKF _ CustomKey。新增WEKF_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。 Add 會傳回錯誤碼,而不會建立新的物件或修改現有物件的任何屬性。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 物件已 啟用 屬性設為 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 HomeWindows 10 Home No
Windows 10 ProWindows 10 Pro No
Windows 10 EnterpriseWindows 10 Enterprise Yes
Windows 10 EducationWindows 10 Education Yes

WEKF _ CustomKeyWEKF_CustomKey

鍵盤篩選器Keyboard Filter