Tuesday, October 8, 2013

ON-OFF Keyboard Lock keys {Caps,Scroll,Num} Using PowerShell.


There is no need to prove that PowerShell is a very cool technology, we already proved it many times.

For me PowerShell is like a blank white canvas and you are painter, now it is up to us and on our imaginations what we can create.

we can create a beautiful usable scripts things using colour full lines.

Ok! now lets come on point,

Today one of my user complained that his password is not working, I reset his password but he still complaining about it, I asked him to check of his CAPSLOCK , key is on , he checked and told me that CAPSLOCK key on/off indicator light is not working,

Finally i went to this seat and i checked , his CAPSLOCK was on and somehow the indicator light was not working,

Once his CAPSLOCK key was set to off , his password started working again.

This problem give me an idea about , what if, i want to check the status of lock keys?, what if I want to on/off lock keys using PowerShell.

After few hours of work, i am successfully able to create a PowerShell script ( Ya , I am using .NET objects too.) for this task.

The script is straight forward and i am added lots of comments in to the script for easy understanding.

When you download the script and run it first time, it will ON your all lock keys :) . (pretty cool) .

For a basic understanding.  i am using “[System.Windows.Forms.Control]::IsKeyLocked('CapsLock')”  to check the status of the CAPSLock key, if the status is true that means Caps lock is ON and if the status is false them that means CAPS Lock is off.

TO  ON/Off the lock key, i am adding Wscript.Shell and  a Powershell Object  “$keyBoardObject = New-Object -ComObject WScript.Shell”  and then I am using  SendKey method to ON lock keys “$keyBoardObject.SendKeys("{CAPSLOCK}")”.

Download Complete Code : http://gallery.technet.microsoft.com/ON-OFF-Keyboad-Lock-keys-6ba9885c



# Creating a WScript.Shell onject

 $keyBoardObject = New-Object -ComObject WScript.Shell



# Getting the status of Keys using .Net Object , this result of the ISkeyLock is in Boolean


# Capsock

 $capsLockKeySatus = [System.Windows.Forms.Control]::IsKeyLocked('CapsLock')




if ( $capsLockKeySatus -eq $false )


              Write-Host "Capslock key is off"


              # if you want to ON the CapsLock {IF CAPSLOCK IS ALREADY OFF }, then please unComment the below Command.




else {              

              Write-Host "Capslock key is On"


              # if you want to OFF the CapsLock Key {IF CAPSLOCK IS ALREADY on }, then please unComment the below Command.

              #-->   $keyBoardObject.SendKeys("{CAPSLOCK}")




Download Complete Code : http://gallery.technet.microsoft.com/ON-OFF-Keyboad-Lock-keys-6ba9885c

I hope you will like it and found it useful.


Aman Dhally

clip_image001 clip_image002 clip_image003 clip_image005  clip_image007


  1. Very Nice and Informative Post. Thanks admin for sharing such an amazing post.

    --->>How to Lock Keyboard and Mouse by KeyFreeze!

  2. Great blog post and really helpful and your blog are very interesting midnightinfo