支持的版本
✅IoT 企业 LTSC
✅ IoT 企业
✅版 LTSC
✅ 企业教育版
✅
添加或删除自定义组合键。
语法
class WEKF_CustomKey {
[Static] uint32 Add(
[In] string CustomKey
);
[Static] uint32 Remove(
[In] string CustomKey
);
[Key] string Id;
[Read, Write] boolean Enabled;
};
成员
下表列出了属于此类的任何方法和属性。
方法
| 方法 | 描述 |
|---|---|
| WEKF_CustomKey.Add | 创建新的自定义组合键,并使键盘筛选器阻止新的组合键。 |
| WEKF_CustomKey.Remove | 删除指定的自定义组合键。 键盘筛选器停止阻止已删除的组合键。 |
属性
| 属性 | 数据类型 | 限定 符 | 描述 |
|---|---|---|---|
| ID | 字符串 | [key] | 自定义组合键的名称。 |
| Enabled | 布尔 | [读取、写入] | 指示密钥是被阻止还是取消阻止。 此属性可以是以下值 - 之一 true 指示密钥被阻止。 - 假指示密钥未被阻止。 |
备注
可以通过在名称中包含修饰键来指定组合键。 最常见的修饰符名称是 >Ctrl、 >Shift、 >Alt 和 >Win。 不能阻止非修改键的组合。 例如,可以阻止 Ctrl +>Shift+>F 的组合>键,但不能阻止 A>+>D 的组合键。
阻止 >Shift 修改的键时,必须输入 Shift> + 未修改的键。 例如,若要阻止>英语键盘布局上的 %键,必须将该键指定为 >Shift+>5。 尝试阻止 >%,会导致键盘筛选器阻止 >5 。
指定要阻止的键组合时,必须使用密钥的英文名称。 有关可以指定的键名称的列表,请参阅键盘筛选器键名称。
示例
以下代码演示如何使用 Windows Management Instrumentation (WMI) 提供程序来添加或启用键盘筛选器将阻止的自定义组合键。 此示例直接修改属性,不调用 WEKF_CustomKey 中定义的任何方法。
<#
.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-Custom-Key($Id) {
<#
.Synopsis
Toggle on a Custom Key Keyboard Filter Rule
.Description
Use Get-WMIObject to enumerate all WEKF_CustomKey instances,
filter against key value "Id", and set that instance's "Enabled"
property to 1/true.
In the case that the Custom instance does not exist, add a new
instance of WEKF_CustomKey using Set-WMIInstance.
.Example
Enable-Custom-Key "Ctrl+V"
Enable filtering of the Ctrl + V sequence.
#>
$custom = Get-WMIObject -class WEKF_CustomKey @CommonParams |
where {
$_.Id -eq "$Id"
};
if ($custom) {
# Rule exists. Just enable it.
$custom.Enabled = 1;
$custom.Put() | Out-Null;
"Enabled Custom Filter $Id.";
} else {
Set-WMIInstance `
-class WEKF_CustomKey `
-argument @{Id="$Id"} `
@CommonParams | Out-Null
"Added Custom Filter $Id.";
}
}
# Some example uses of the function defined above.
Enable-Custom-Key "Ctrl+V"
Enable-Custom-Key "Numpad0"
Enable-Custom-Key "Shift+Numpad1"