I would like to be able toggle on and off the "Num Lock" key on the keyboard. I have tried multiple examples around the web and here, with no success. This is the closest thing I've got to a solution:
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("{NUMLOCK}")
The above code looks like it might work and I see the "Num Lock" indicator on my keyboard flash for a second but it doesn't "stick".
Techopedia Explains Toggle Key The most commonly used toggle key is the caps lock key, which alternates the letter keys between uppercase and lowercase. Num lock is another toggle key which helps to input numerals from the numeric keyboard and is turned on by default.
The NmLk key is located on the top, right hand side of the keyboard. Sometimes it is on the same key as F8, F7, or Insert. Press Fn+F8, F7, or Insert to enable/disable numlock. For 15-inch or above laptops, the numeric keypad is located on the right side of the keyboard.
Stumbled here looking for a way to keep Num Lock
ON eternally (apparently the word "lock" doesn't mean much 🤷♂️). This script checks Num Lock
status every 2 seconds, and switches it back on if it's been turned off:
$wsh = New-Object -ComObject WScript.Shell
while($true){
if ([console]::NumberLock -eq $false) {
$wsh.SendKeys('{NUMLOCK}')
}
Start-Sleep 2
}
I think it would be a good candidate for converting into a standalone tiny .exe using PS2EXE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With