Disable Caps Lock

mail@pastecode.io avatar
unknown
batchfile
a year ago
1.2 kB
1
Indexable
Never
@echo off
setlocal enabledelayedexpansion

rem Get the current Caps Lock state
wmic path win32_Keyboard get capslockstate > state.txt
set /p state=<state.txt
del state.txt

rem Toggle the Caps Lock state
if !state!==0 (
    echo Caps Lock is off
    powershell.exe -command "Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;class CapsLock{[DllImport(\"user32.dll\")]public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);public static void Main(){keybd_event(0x14,0x45,0x1,0);keybd_event(0x14,0x45,0x1 | 0x2,0);}}' -ReferencedAssemblies System.Runtime.InteropServices; [CapsLock]::Main()")
    echo Caps Lock has been turned on
) else (
    echo Caps Lock is on
    powershell.exe -command "Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;class CapsLock{[DllImport(\"user32.dll\")]public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);public static void Main(){keybd_event(0x14,0x45,0x1,0);keybd_event(0x14,0x45,0x1 | 0x2,0);}}' -ReferencedAssemblies System.Runtime.InteropServices; [CapsLock]::Main()")
    echo Caps Lock has been turned off
)