function Set-CapsLock([switch]$Disable = $true)
{
$CapsCtrl = @"
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class CapsLockControl
{
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,UIntPtr dwExtraInfo);
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
public static void Main()
{
if (Control.IsKeyLocked(Keys.CapsLock))
{
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr) 0);
keybd_event(0x14, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
(UIntPtr) 0);
}
}
}
"@
if (-not [CapsLockControl]) {
Add-Type $CapsCtrl -ReferencedAssemblies System.Windows.Forms
}
if ($Disable) {
[CapsLockControl]::Main()
Write-Host "Capslock has been disabled"
}
}
Set-CapsLock –Disable
http://cboard.cprogramming.com/csharp-programming/105103-how-detect-capslock-csharp.html
Fuente: http://trevorsullivan.net/2010/10/13/powershell-disable-capslock/
No hay comentarios:
Publicar un comentario