WEKF_CustomKey.Add

Membuat kombinasi tombol kustom baru dan mengaktifkan Filter Keyboard untuk memblokir kombinasi tombol baru.

Sintaks

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

Parameter

CustomKey
[in] Kombinasi kunci kustom untuk ditambahkan. Untuk daftar nama kunci yang valid, lihat Nama kunci Filter Keyboard.

Tampilkan Nilai

Mengembalikan nilai HRESULT yang menunjukkan Konstanta Non-Kesalahan WMI atau Konstanta Kesalahan WMI.

Keterangan

WEKF_CustomKey.Add membuat objek WEKF_CustomKey baru dan mengatur properti Diaktifkan dari objek baru ke true, dan properti Id ke CustomKey.

Jika objek WEKF_CustomKey sudah ada dengan properti Id yang sama dengan CustomKey, maka WEKF_CustomKey.Add mengembalikan kode kesalahan dan tidak membuat objek baru atau memodifikasi properti apa pun dari objek yang ada. Jika objek WEKF_CustomKey yang ada memiliki properti Diaktifkan yang diatur ke false, Filter Keyboard tidak memblokir kombinasi tombol kustom.

Contoh

Kode berikut menunjukkan cara menambahkan atau mengaktifkan kunci kustom yang akan diblokir Filter Keyboard dengan menggunakan penyedia Windows Management Instrumentation (WMI) untuk Filter Keyboard.

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

Persyaratan

Edisi Windows Didukung
Windows Home Tidak
Windows Pro Tidak
Windows Enterprise Ya
Windows Education Ya
Windows IoT Enterprise Ya