WEKF_CustomKey.Add

建立新的自訂按鍵組合,並讓鍵盤篩選器封鎖新的按鍵組合。

語法

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

參數

CustomKey
[in]要加入的自訂按鍵組合。 如需有效按鍵名稱的清單,請參閱 鍵盤篩選按鍵名稱

傳回值

傳回 HRESULT 值,指出 WMI 非錯誤常數WMI 錯誤常數

備註

WEKF_CustomKey.Add 會建立新的 WEKF_CustomKey 物件,並將新物件的 Enabled 屬性設定為 true,並將 Id 屬性設定為 CustomKey

如果 id屬性等於CustomKeyWEKF_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 10 Home
Windows 10 Pro No
Windows 10 Enterprise
Windows 10 Education

WEKF_CustomKey

鍵盤篩選器