Merkwürdiger GetKeyNameText auf allen meinen Computern

11/01/2011 - 19:08 von Georg Jung | Report spam
Könnte jemand mir erklàren, warum vbKeyHome und vbKeyNumpad7 mir beide
denselben Namen zurückgeben, nàmlich 7 (ZEHNERTASTATUR)? Getestet auf XP
und Vista.

Option Explicit

Private Declare Function GetVersion Lib "kernel32" () As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(lpDest As Any, lpSource As Any, ByVal nCount As Long)
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA"
(ByVal cChar As Byte) As Integer
Private Declare Function VkKeyScanW Lib "user32" (ByVal cChar As
Integer) As Integer
Private Declare Function MapVirtualKey Lib "user32" Alias
"MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function MapVirtualKeyW Lib "user32" (ByVal wCode As
Long, ByVal wMapType As Long) As Long
Private Declare Function GetKeyNameText Lib "user32" Alias
"GetKeyNameTextA" (ByVal lParam As Long, ByVal lpBuffer As String, ByVal
nSize As Long) As Long
Private Declare Function GetKeyNameTextW Lib "user32" (ByVal lParam As
Long, ByVal lpBuffer As Long, ByVal nSize As Long) As Long

Private Function GetKeyText(ByVal KeyCode As KeyCodeConstants) As String

Dim ScanCodeLng As Long
Dim ScanCodeByte(3) As Byte
Dim lParamLng As Long
Dim lParamByte(3) As Byte
Dim TmpBuffer As String * 256

' Scancode ermitteln (tastaturspezifische Tasten-ID)
ScanCodeLng = MapVirtualKey(KeyCode, 0)
CopyMemory ScanCodeByte(0), ScanCodeLng, 4

' lParam zusammenbauen
lParamByte(0) = 1
lParamByte(2) = ScanCodeByte(0)
CopyMemory lParamLng, lParamByte(0), 4

' Text der Taste ermitteln
Call GetKeyNameText(lParamLng, TmpBuffer, Len(TmpBuffer))

GetKeyText = StrConv(Left(TmpBuffer, InStr(1, TmpBuffer, vbNullChar)
- 1), vbProperCase)

End Function

Private Sub Form_Load()

MsgBox vbKeyHome & ": " & GetKeyText(vbKeyHome)
MsgBox vbKeyNumpad7 & ": " & GetKeyText(vbKeyNumpad7)

End Sub
 

Lesen sie die antworten

#1 Georg Jung
11/01/2011 - 19:25 | Warnen spam
Ich habe hier wohl die Antwort, aber kann mir jemand erklàren, wie ich
mit VB6 das extended bit setze?

switch (virtualKey)
{
case VK_LEFT: case VK_UP: case VK_RIGHT: case VK_DOWN: // arrow
keys
case VK_PRIOR: case VK_NEXT: // page up and page down
case VK_END: case VK_HOME:
case VK_INSERT: case VK_DELETE:
case VK_DIVIDE: // numpad slash
case VK_NUMLOCK:
{
scanCode |= 0x100; // set extended bit
break;
}
}


Vielen Dank! Ich kann leider kein C++.

Ähnliche fragen