Numlock, Capslock und Scrollock
[Windows 95/98/NT/ME/2000]

11.07.2001


Diese Tasten können Sie entweder ein- bzw. ausschalten,
    oder aber den Status abfragen.

ERFORDERLICHE OBJEKTE
   3 Checkboxes (Check1, Check2, Check3)
      3 CommandButtons (Command1, Command2, Command3)     

FORM-CODE
   Private Declare Function GetKeyboardState Lib "user32" _
      (pbKeyState As Byte) As Long
   Private Declare Function GetKeyState Lib "user32" _
      (ByVal nVirtKey As Long) As Integer
   Private Declare Function GetVersionEx Lib "kernel32" _
      Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
   Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
      ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
   Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
   Private Const VER_PLATFORM_WIN32_NT = 2
   Private Const VER_PLATFORM_WIN32_WINDOWS = 1
   Private Const KEYEVENTF_EXTENDEDKEY = &H1
   Private Const KEYEVENTF_KEYUP = &H2
   Private Const VK_CAPS = &H14
   Private Const VK_NUM = &H90
   Private Const VK_SCROLL = &H91
   Private keys(0 To 255) As Byte
   Private Type OSVERSIONINFO
      dwOSVersionInfoSize As Long
      dwMajorVersion As Long
      dwMinorVersion As Long
      dwBuildNumber As Long
      dwPlatformId As Long
      szCSDVersion As String * 128
   End Type
   Private oSv As OSVERSIONINFO
   Public Function Status(Taste) As Boolean
      Dim bInsertKeyState As Boolean
      oSv.dwOSVersionInfoSize = Len(oSv)
      GetVersionEx oSv
      GetKeyboardState keys(0)
      Status = keys(Taste)
   End Function
   Public Sub Switch(Taste, AnAus As Boolean)
      If (Status(Taste) <> AnAus) Then
         If (oSv.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS) Then
            keys(Taste) = 1
            SetKeyboardState keys(0)
         ElseIf (oSv.dwPlatformId = VER_PLATFORM_WIN32_NT) Then
            keybd_event Taste, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
            keybd_event Taste, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
         End If
      End If
   End Sub
   Private Sub Check1_Click()
      Switch VK_NUM, Check1.Value
   End Sub
   Private Sub Check2_Click()
      Switch VK_CAPS, Check2.Value
   End Sub
   Private Sub Check3_Click()
      Switch VK_SCROLL, Check3.Value
   End Sub
   Private Sub Command1_Click()
      MsgBox Status(VK_NUM), vbExclamation, "Tastenstatus"
   End Sub
   Private Sub Command2_Click()
      MsgBox Status(VK_CAPS), vbExclamation, "Tastenstatus"
   End Sub
   Private Sub Command3_Click()
      MsgBox Status(VK_SCROLL), vbExclamation, "Tastenstatus"
   End Sub
 

Download - 2 KB