WEKF_Scancode

使用鍵盤掃描程式碼封鎖或解除封鎖按鍵組合,這是每當按下或放開按鍵時所產生的整數數位。

語法

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

成員

下表列出屬於這個類別的任何建構函式、方法、欄位和屬性。

方法

方法 描述
WEKF_Scancode.Add 新增新的自訂掃描碼組合,並啟用鍵盤篩選來封鎖新的掃描碼組合。
WEKF_Scancode.Remove 移除指定的自訂掃描代碼組合。 鍵盤篩選會停止封鎖已移除的掃描代碼組合。

屬性

屬性 資料類型 限定詞 描述
修飾詞 string [key] 屬於要封鎖之按鍵組合的修飾詞鍵。
Scancode uint16 [key] 要封鎖之按鍵組合的掃描程式碼部分。
Enabled Boolean [讀取,寫入] 指出掃描碼遭到封鎖或解除封鎖。 此屬性可以是下列其中一個值:
- true表示掃描程式碼遭到封鎖。
- 表示掃描程式碼未遭到封鎖。

備註

每當按下按鍵時,鍵盤會產生掃描碼。 不論系統目前正在使用哪一個鍵盤配置,相同的實體按鍵一律會產生相同的掃描碼。

您可以在Add方法的Modifiers參數中包含修飾詞索引鍵,或是修改Modifiers屬性來指定按鍵組合。 最常見的修飾詞名稱是 「Ctrl」、「Shift」、「Alt」 和 「Win」。

範例

下列程式碼示範如何使用鍵盤篩選的 Windows Management Instrumentation (WMI) 提供者,新增或啟用鍵盤篩選將會封鎖的鍵盤掃描程式碼。 本範例會直接修改屬性,而且不會呼叫 WEKF_Scancode中定義的任何方法。

<#
.Synopsis
    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
    locally.
#>
param (
    [String] $ComputerName
)

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


function Enable-Scancode($Modifiers, [int]$Code) {
    <#
    .Synopsis
        Toggle on a Scancode Keyboard Filter Rule
    .Description
        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.
    .Example
        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 首頁 No
Windows 專業版
Windows 企業版
Windows 教育版
Windows IoT 企業版 是的

鍵盤篩選器 WMI 提供者參考資料

鍵盤篩選器