vb.net Code:
Imports System.Runtime.InteropServices Public Class Form2 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 KEYEVENTF_EXTENDEDKEY As Integer = &H1 Private Const KEYEVENTF_KEYUP As Integer = &H2 Private Sub Button1_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs _ ) Handles Button1.Click ' Toggle CapsLock ' Simulate the Key Press keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0) ' Simulate the Key Release keybd_event(VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0) End Sub 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




Reply With Quote