Controlar el teclado en VB
Hola, necesito ayuda con un problema inesperado que me sucede con un proyecto q consiste en un juego. Para controlar los movimientos, utilizo el teclado, y si utilizas los eventos de teclado como el keydown te limita el numero de teclas que pulsas a la vez. Supongamos que quiero hacer un piano, pues no podria tocar muchas notas simultaneas. He buscado en la red, y no he encontrado nada de gran ayuda, en una pagina inglesa, se supone que te facilitaban un codigo, pero no sirve para nada, el problema continua. Alguien saabe como podria solucionarlo??
Hola: por mis pocos conocimientos y mis intentos de dominar el teclado en BV, podria decir que no es posible comandar a dos teclas al mismo tiempo.
Pero debería haber una solución, no se... Por ejemplo las DirectX tienen el Direct Input que controla el teclado, es un ejemplo estupido, porque eso ya lo he probado y sigue sin funcionar, pero seguro que hay alguna solucion. Alguien me puede ayudaar?
No es imposible, mira este ejemplo. Necesitas un timer
y un array de controles Label llamado Label1:
Dim tecla(3) As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
tecla(0) = True
If tecla(1) Then tecla(1) = False
Case vbKeyDown
tecla(1) = True
If tecla(0) Then tecla(0) = False
Case vbKeyLeft
tecla(2) = True
If tecla(3) Then tecla(3) = False
Case vbKeyRight
tecla(3) = True
If tecla(2) Then tecla(2) = False
End Select
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
tecla(0) = False
Case vbKeyDown
tecla(1) = False
Case vbKeyLeft
tecla(2) = False
Case vbKeyRight
tecla(3) = False
End Select
End Sub
Private Sub Timer1_Timer()
Dim i As Integer
For i = 0 To 3
Label1(i).Caption = "Tecla(" & CStr(i) & ") = " & tecla(i)
Next i
End Sub
y un array de controles Label llamado Label1:
Dim tecla(3) As Boolean
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
tecla(0) = True
If tecla(1) Then tecla(1) = False
Case vbKeyDown
tecla(1) = True
If tecla(0) Then tecla(0) = False
Case vbKeyLeft
tecla(2) = True
If tecla(3) Then tecla(3) = False
Case vbKeyRight
tecla(3) = True
If tecla(2) Then tecla(2) = False
End Select
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
tecla(0) = False
Case vbKeyDown
tecla(1) = False
Case vbKeyLeft
tecla(2) = False
Case vbKeyRight
tecla(3) = False
End Select
End Sub
Private Sub Timer1_Timer()
Dim i As Integer
For i = 0 To 3
Label1(i).Caption = "Tecla(" & CStr(i) & ") = " & tecla(i)
Next i
End Sub
