Results 1 to 1 of 1

Thread: Toggle(Turn On/Off) Caps Lock/Num Lock/Scroll Lock keys

  1. #1

    Thread Starter
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Toggle(Turn On/Off) Caps Lock/Num Lock/Scroll Lock keys

    vb.net Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Public Class Form2
    4.  
    5.     Private Declare Sub keybd_event Lib "user32" ( _
    6.         ByVal bVk As Byte, _
    7.         ByVal bScan As Byte, _
    8.         ByVal dwFlags As Integer, _
    9.         ByVal dwExtraInfo As Integer _
    10.     )
    11.  
    12.     Private Const VK_CAPITAL As Integer = &H14
    13.     Private Const KEYEVENTF_EXTENDEDKEY As Integer = &H1
    14.     Private Const KEYEVENTF_KEYUP As Integer = &H2
    15.  
    16.     Private Sub Button1_Click( _
    17.         ByVal sender As System.Object, _
    18.         ByVal e As System.EventArgs _
    19.     ) Handles Button1.Click
    20.  
    21.         ' Toggle CapsLock
    22.  
    23.         ' Simulate the Key Press
    24.         keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0)
    25.        
    26.         ' Simulate the Key Release
    27.         keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
    28.     End Sub
    29.  
    30. End Class

    You can use the above code to toggle NUM LOCK and SCROLL LOCK keys, you just need to replace VK_CAPITAL with appropriate constant variables of NUM LOCK and SCROLL LOCK keys. The constant variables of NUM LOCK and SCROLL LOCK keys are as below:

    Code:
    Private Const VK_NUMLOCK As Integer = &H90
    Private Const VK_SCROLL As Integer = &H91

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width