Skip to content

Instantly share code, notes, and snippets.

@atao
Last active October 1, 2023 19:37
Show Gist options
  • Save atao/12b5857d388068bab134d5f9c36241b1 to your computer and use it in GitHub Desktop.
Save atao/12b5857d388068bab134d5f9c36241b1 to your computer and use it in GitHub Desktop.
⌨️ Lock keyboard and mouse during n seconds.
#Run As Administrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
$code = @"
[DllImport("user32.dll")]
public static extern bool BlockInput(bool fBlockIt);
"@
$userInput = Add-Type -MemberDefinition $code -Name UserInput -Namespace UserInput -PassThru
function Disable-UserInput($seconds) {
$userInput::BlockInput($true)
Start-Sleep $seconds
$userInput::BlockInput($false)
}
Disable-UserInput -seconds 4 | Out-Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment