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 | 删除指定的自定义扫描代码组合。 键盘筛选器停止阻止已删除的扫描代码组合。 |
属性
属性 | 数据类型 | 限定 符 | 描述 |
---|---|---|---|
修饰 符 | 字符串 | [key] | 要阻止的组合键的修饰键。 |
扫描代码 | uint16 | [key] | 要阻止的组合键的扫描代码部分。 |
Enabled | 布尔 | [读取、写入] | 指示扫描代码是被阻止还是取消阻止。 此属性可以是以下值之一: - 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