Switch On/Off NumLock,CapsLock,ScrollLock In VB.NET

i hope this will be something more interesting and useful than others so this what actually do is , you can make two buttons on is for switching the NumLock,CapsLock and ScrollLock on and the other button is to switch of them all ok so create a new project and name them whatever you like to , add two buttons

now double click your form and erase everything and add this code

Public Class form1

    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)

    Private Const VK_CAPITAL As Integer = &H14
    Private Const VK_SCROLL As Integer = &H91
    Private Const VK_NUMLOCK As Integer = &H90

    Private Const KEYEVENTF_EXTENDEDKEY As Integer = &H1
    Private Const KEYEVENTF_KEYUP As Integer = &H2
end class


so that is the keyboard event library we are using

this is CapsLock -  Private Const VK_CAPITAL As Integer = &H14

this is ScrollLock -  Private Const VK_SCROLL As Integer = &H91

this is NumLock -  Private Const VK_NUMLOCK As Integer = &H90

now double click your button1(on) and add this code
     
 keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
        keybd_event(VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
        keybd_event(VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)

now double click your button2 (off) and add the code below
  
     keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
        keybd_event(VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
        keybd_event(VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)

 now click debug and see if its working

you can also on the NumLock,CapsLock,ScrollLock or off them , single or else i can say switch them one by one

add three buttons and for

Num Lock 

  On -    keybd_event(VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)

Off -   keybd_event(VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)

Caps Lock

On -  keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)

Off - keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)

Scroll Lock

On -  keybd_event(VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)

Off -  keybd_event(VK_SCROLL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)


if you get any problems comment 

4 comments

O:-)

Reply

great

Reply

This code is EXTREMELY awesome! Thank you for keeping the planet spinning!

Reply

Works Great !!!!!! thank you

Reply

Post a Comment