WEKF_CustomKey.Add
新しいカスタム キーの組み合わせを作成し、キーボード フィルターで新しいキーの組み合わせをブロックできるようにします。
構文
[Static] uint32 Add(
[In] string CustomKey
);
パラメーター
CustomKey[入力]追加するカスタム キーの組み合わせ。 有効なキー名の一覧については、「キーボード フィルターのキー名」を参照してください。
戻り値
WMI のエラー以外の定数または WMI エラー定数を示す HRESULT 値を返します。
注釈
WEKF_CustomKey.Add は、新しい WEKF_CustomKey オブジェクトを作成し、新しいオブジェクトの Enabled プロパティを true に、Id プロパティを CustomKey に設定します。
Id プロパティが CustomKey である WEKF_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 Pro | いいえ |
Windows Enterprise | はい |
Windows Education | はい |
Windows IoT Enterprise | はい |