Die folgenden
Routinen setzen oder ermitteln den Status der Tasten
Numlock, Capslock und Scroll-Lock:
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
Private Function KeyStatus(Taste) As Boolean
Dim bInsertKeyState As Boolean
oSv.dwOSVersionInfoSize = Len(oSv)
GetVersionEx oSv
GetKeyboardState keys(0)
KeyStatus = keys(Taste)
End Function
Private Sub Switch(Taste, AnAus As Boolean)
If (KeyStatus(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
Public Sub An()
Switch VK_NUM, 1
Switch VK_CAPS, 1
Switch VK_SCROLL, 1
End Sub
Public Sub Aus()
Switch VK_NUM, 0
Switch VK_CAPS, 0
Switch VK_SCROLL, 0
End Sub
Public Sub Status()
MsgBox "Num : " & KeyStatus(VK_NUM) & vbNewLine & _
"Caps: " & KeyStatus(VK_CAPS) & vbNewLine & _
"Scroll: " & KeyStatus(VK_SCROLL), _
vbExclamation, "Tastenstatus"
End Sub
|