使用鍵盤掃描碼來封鎖或解除封鎖按鍵組合,這是每次按下或釋放按鍵時所產生的整數數位。Blocks or unblocks key combinations by using the keyboard scan code, which is an integer number that is generated whenever a key is pressed or released.


class WEKF_Scancode {
    [Static] uint32 Add(
        [In] string Modifiers,
        [In] uint16 scancode
    [Static] uint32 Remove(
        [In] string Modifiers,
        [In] uint16 Scancode

    [Key] string Modifiers;
    [Key] uint16 Scancode;
    [Read, Write] boolean Enabled;


下表列出屬於這個類別的任何函式、方法、欄位和屬性。The following tables list any constructors, methods, fields, and properties that belong to this class.


方法Methods 描述Description


加入新的自訂掃描程式碼組合,並啟用鍵盤篩選器以封鎖新的掃描程式碼組合。Adds a new custom scan code combination and enables Keyboard Filter to block the new scan code combination.


移除指定的自訂掃描程式碼組合。Removes the specified custom scan code combination. 鍵盤篩選器會停止封鎖已移除的掃描程式碼組合。Keyboard Filter stops blocking the scan code combination that was removed.


屬性Property 資料類型Data type 限定詞Qualifiers 描述Description




屬於要封鎖之按鍵組合的輔助按鍵。The modifier keys that are part of the key combination to block.




要封鎖之按鍵組合的掃描程式碼部分。The scan code part of the key combination to block.



[讀取、寫入][read, write]

指出掃描程式碼是否已封鎖或解除封鎖。Indicates whether the scan code is blocked or unblocked. 這個屬性可以是下列其中一個值:This property can be one of the following values:

Value 描述Description


表示已封鎖掃描程式碼。Indicates that the scan code is blocked.


指出不封鎖掃描程式碼。Indicates that the scan code is not blocked.



每次按下按鍵時,鍵盤就會產生掃描代碼。Scan codes are generated by the keyboard whenever a key is pressed. 相同的實體金鑰一律會產生相同的掃描程式碼,不論系統目前正在使用哪一種鍵盤配置。The same physical key will always generate the same scan code, regardless of which keyboard layout is currently being used by the system.

您可以藉由在Add方法的修飾詞參數中包含輔助按鍵,或修改修飾詞屬性來指定按鍵組合。You can specify key combinations by including the modifier keys in the Modifiers parameter of the Add method or by modifying the Modifiers property. 最常見的修飾詞名稱是「Ctrl」、「Shift」、「Alt」和「Win」。The most common modifier names are “Ctrl”, “Shift”, “Alt”, and “Win”.


下列程式碼示範如何使用鍵盤篩選的 Windows Management Instrumentation (WMI)提供者,新增或啟用鍵盤篩選器所封鎖的鍵盤掃描程式碼。The following code demonstrates how to add or enable a keyboard scan code that Keyboard Filter will block by using the Windows Management Instrumentation (WMI) providers for Keyboard Filter. 這個範例會直接修改屬性,而不會呼叫WEKF_Scancode中定義的任何方法。This example modifies the properties directly, and does not call any of the methods defined in WEKF_Scancode.

    This script shows how to use the WMI provider to enable and add 
    Keyboard Filter rules through Windows Powershell on the local computer.
.Parameter ComputerName
    Optional parameter to specify a remote machine that this script should
    manage.  If not specified, the script will execute all WMI operations
param (
    [String] $ComputerName

$CommonParams = @{"namespace"="root\standardcimv2\embedded"}
$CommonParams += $PSBoundParameters

function Enable-Scancode($Modifiers, [int]$Code) {
        Toggle on a Scancode Keyboard Filter Rule
        Use Get-WMIObject to enumerate all WEKF_Scancode instances,
        filter against key values of "Modifiers" and "Scancode", and set
        that instance's "Enabled" property to 1/true.

        In the case that the Scancode instance does not exist, add a new
        instance of WEKF_Scancode using Set-WMIInstance.
        Enable-Predefined-Key "Ctrl+V"

        Enable filtering of the Ctrl + V sequence.

    $scancode =
        Get-WMIObject -class WEKF_Scancode @CommonParams |
            where {
                ($_.Modifiers -eq $Modifiers) -and ($_.Scancode -eq $Code)

    if($scancode) {
        $scancode.Enabled = 1
        $scancode.Put() | Out-Null
        "Enabled Custom Scancode {0}+{1:X4}" -f $Modifiers, $Code
    } else {
        Set-WMIInstance `
            -class WEKF_Scancode `
            -argument @{Modifiers="$Modifiers"; Scancode=$Code} `
            @CommonParams | Out-Null
        "Added Custom Scancode {0}+{1:X4}" -f $Modifiers, $Code

# Some example uses of the function defined above.

Enable-Scancode "Ctrl" 37


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

鍵盤篩選器 WMI 提供者參考資料Keyboard Filter WMI provider reference

鍵盤篩選器Keyboard Filter