Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: Psyke1 en Diciembre 27, 2010, 05:29:46 am
-
Cual es la mejor manera de:
Detectar la pulsacion de 3 teclas (por ej A+S+D)
Entonces se imprimiria una sola vez:
Debug.Print Las teclas A+S+D se presionaron
Y cundo soltara una de esas tres o todas saliera se imprimier este otro mensaje:
Debug.Print Las teclas A+S+D se soltaron
Yo lo intenté por un hook:
'...
Private Function KeyProc(ByVal nCode As Long, ByVal wParam As Long, lParam As Long) As Long
If GetAsyncKeyState(vbKeyA) And GetAsyncKeyState(vbKeyS) And GetAsyncKeyState(vbKeyD) Then
If wParam = WM_KEYDOWN Then
Debug.Print "Se presionarion las teclas a+s+d --> "; Time$
ElseIf wParam = WM_KEYUP Then
Debug.Print "Se soltaron las teclas a+s+d --> "; Time$
End If
End If
KeyProc = CallNextHookEx(hKeyBoardHook, nCode, wParam, lParam)
End Function
El problema es que cuando presiono me imprime el mensaje varias veces... :S
Quizás me recomendeis otra forma de hacerlo, ¿hotkeys quizás?
Gracias! :D
-
Hola, yo creo que la unica forma es poniendo una variable booleana de tipo bandera.
Saludos.
-
Eso había pensado, aahora consigo el resultado que quiero así:
Private Function KeyProc(ByVal nCode As Long, ByVal wParam As Long, lParam As Long) As Long
Select Case KeysPressed
Case 1
If wParam = WM_KEYDOWN And b = False Then
Debug.Print "Se presionarion las teclas a+s+d --> "; Time$
b = True
ElseIf wParam = WM_KEYUP Then
Debug.Print "Se soltaron las teclas a+s+d --> "; Time$
b = False
End If
Case 2
If wParam = WM_KEYDOWN And b = False Then
Debug.Print "Se presionarion las teclas q+w+e --> "; Time$
b = True
ElseIf wParam = WM_KEYUP Then
Debug.Print "Se soltaron las teclas q+w+e --> "; Time$
b = False
End If
Case 3
If wParam = WM_KEYDOWN And b = False Then
Debug.Print "Se presionarion las teclas z+x+c --> "; Time$
b = True
ElseIf wParam = WM_KEYUP Then
Debug.Print "Se soltaron las teclas z+x+c --> "; Time$
b = False
End If
End Select
KeyProc = CallNextHookEx(hKeyBoardHook, nCode, wParam, lParam)
End Function
Private Function KeysPressed() As Long
If (GetAsyncKeyState(vbKeyA) And GetAsyncKeyState(vbKeyS) And GetAsyncKeyState(vbKeyD)) Then
KeysPressed = 1
ElseIf (GetAsyncKeyState(vbKeyQ) And GetAsyncKeyState(vbKeyW) And GetAsyncKeyState(vbKeyE)) Then
KeysPressed = 2
ElseIf (GetAsyncKeyState(vbKeyZ) And GetAsyncKeyState(vbKeyX) And GetAsyncKeyState(vbKeyC)) Then
KeysPressed = 3
End If
End Function
Lo que pasaba es que me parecía feo... :P
DoEvents! :P