WEKF_Scancode
支援的版本
✅IoT 企業版 LTSC
✅ IoT 企業✅
版 LTSC
✅ 企業
✅教育版
使用鍵盤掃描程式代碼封鎖或解除封鎖按鍵組合,這是每次按下或放開按鍵時所產生的整數。
語法
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] | 要封鎖之按鍵組合的掃描程序代碼部分。 |
啟用 | 布林值 | [讀取、寫入] | 指出掃描程式代碼是否遭到封鎖或解除封鎖。 此屬性可以是下列其中一個值: - 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