Rimuovere le configurazioni delle combinazioni di tasti

Edizioni
✅ supportate IoT Enterprise LTSC
✅ IoT Enterprise
✅ Enterprise LTSC
✅ Enterprise
✅ Education

Lo script di esempio seguente di Windows PowerShell usa i provider di Strumentazione gestione Windows (WMI) per Filtro tastiera per creare due funzioni che rimuovono le configurazioni personalizzate delle regole di blocco. La rimozione di una regola comporta l'eliminazione di tale configurazione, ma un'altra regola attiva potrebbe comunque bloccare lo stesso input fisico.

La prima funzione, Remove-Custom-Key, rimuove le regole di blocco della chiave personalizzata.

La seconda funzione, Remove-Scancode, rimuove le regole di blocco del codice di scansione.

Non è possibile rimuovere le regole di blocco a chiave predefinita, ma è possibile disattivarle impostando la relativa Enabled proprietà su 0.

Remove-rules.ps1

#
# Copyright (C) Microsoft. All rights reserved.
#

<#
.Synopsis
    This script uses the built-in WMI providers to remove Keyboard Filter blocking rules. WEKF_PredefinedKey rules can't be removed.
.Parameter ComputerName
    Optional parameter to specify the remote computer 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 Remove-Custom-Key($Id) {
    <#
    .Synopsis
        Remove a WEKF_CustomKey blocking rule.
    .Description
        Enumerate all WEKF_CustomKey instances. When an instance has an Id that
        matches $Id, delete it.
    .Example
        Remove-Custom-Key "Ctrl+V"

        Removes the WEKF_CustomKey blocking rule for Ctrl+V.
#>

    $customInstance = Get-WMIObject -class WEKF_CustomKey @CommonParams |
        where {$_.Id -eq $Id}

    if ($customInstance) {
        $customInstance.Delete();
        "Removed custom-key blocking rule for $Id.";
    } else {
        "Custom-key blocking rule for $Id does not exist.";
    }
}

function Remove-Scancode($Modifiers, [int]$Code) {
    <#
    .Synopsis
        Remove a WEKF_Scancode blocking rule.
    .Description
        Enumerate all WEKF_Scancode instances. When an instance has matching
        Modifiers and Scancode values, delete it.
    .Example
        Remove-Scancode "Ctrl" 37

        Removes the WEKF_Scancode blocking rule with Modifiers="Ctrl" and
        Scancode=37.
#>

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

    if ($scancodeInstance) {
        $scancodeInstance.Delete();
        "Removed scan-code blocking rule for $Modifiers+$Code";
    } else {
        "Scan-code blocking rule for $Modifiers+$Code does not exist.";
    }
}

# Some example uses of the functions defined above.
Remove-Custom-Key "Ctrl+V"
Remove-Custom-Key "Numpad0"
Remove-Custom-Key "Shift+Numpad1"
Remove-Custom-Key "Shift+5"
Remove-Scancode "Ctrl" 37

Esempi di script di Windows PowerShell per il filtro della tastiera

Filtro tastiera Informazioni di riferimento sui provider WMI

Filtro della tastiera