Keypress - VB

AlmaMater

Power Member
Olá,

Precisava de umas dicas... andei a pesquisar mas apenas encontro a forma de identificar uma determinada tecla! O que eu queria era como se faz num jogo de carros por exemplo.. estou a carregar na tecla do cursor para cima e ao mesmo tempo carrego na tecla do cursor da direita e o carro anda pa frente e vira pa direita..

ou seja, conseguir identificar que ambas as teclas estão a ser pressionadas ao mesmo tempo.. é possível?

thanks
 
O vb não está preparado para isso.

Segundo o que sei é extremamente complicado mas experimenta pesquisas no google, pode ser que alguem tenha descoberto como o fazer.

Também nunca precisei.. Experimenta por DirectInput
 
Eu não entendo muito bem a tua pergunta, porque cada tecla funciona independentemente. Só tens é de testar condições quando qualquer tecla é pressionada ou solta.

Vê esta pequena brincadeira ... cria um novo projecto em VB2008 e coloca lá este código para mostar isto mesmo:

Código:
  Private lblUP As Label
    Private lblDOWN As Label
    Private lblLEFT As Label
    Private lblRIGHT As Label
    Private Sub changeLabelStatus(ByVal action As String, ByVal key As Windows.Forms.Keys)
        Select Case key
            Case Keys.Up
                lblUP.Text = String.Format("{0} {1}", action, key.ToString)
            Case Keys.Down
                lblDOWN.Text = String.Format("{0} {1}", action, key.ToString)
            Case Keys.Right
                lblRIGHT.Text = String.Format("{0} {1}", action, key.ToString)
            Case Keys.Left
                lblLEFT.Text = String.Format("{0} {1}", action, key.ToString)
        End Select
    End Sub
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        changeLabelStatus("DOWN:", e.KeyCode)
    End Sub
    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        changeLabelStatus("UP", e.KeyCode)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
        lblUP = New Label With {.Text = String.Empty, .Top = 0}
        lblDOWN = New Label With {.Text = String.Empty, .Top = 25}
        lblLEFT = New Label With {.Text = String.Empty, .Top = 50}
        lblRIGHT = New Label With {.Text = String.Empty, .Top = 75}
        Me.Controls.AddRange(New Control() {lblUP, lblDOWN, lblLEFT, lblRIGHT})
    End Sub
 
Eu não entendo muito bem a tua pergunta, porque cada tecla funciona independentemente. Só tens é de testar condições quando qualquer tecla é pressionada ou solta.

Vê esta pequena brincadeira ... cria um novo projecto em VB2008 e coloca lá este código para mostar isto mesmo:

Código:
  Private lblUP As Label
    Private lblDOWN As Label
    Private lblLEFT As Label
    Private lblRIGHT As Label
    Private Sub changeLabelStatus(ByVal action As String, ByVal key As Windows.Forms.Keys)
        Select Case key
            Case Keys.Up
                lblUP.Text = String.Format("{0} {1}", action, key.ToString)
            Case Keys.Down
                lblDOWN.Text = String.Format("{0} {1}", action, key.ToString)
            Case Keys.Right
                lblRIGHT.Text = String.Format("{0} {1}", action, key.ToString)
            Case Keys.Left
                lblLEFT.Text = String.Format("{0} {1}", action, key.ToString)
        End Select
    End Sub
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        changeLabelStatus("DOWN:", e.KeyCode)
    End Sub
    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        changeLabelStatus("UP", e.KeyCode)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
        lblUP = New Label With {.Text = String.Empty, .Top = 0}
        lblDOWN = New Label With {.Text = String.Empty, .Top = 25}
        lblLEFT = New Label With {.Text = String.Empty, .Top = 50}
        lblRIGHT = New Label With {.Text = String.Empty, .Top = 75}
        Me.Controls.AddRange(New Control() {lblUP, lblDOWN, lblLEFT, lblRIGHT})
    End Sub

Amigo!! Acho que acabaste de me resolver o problema :D ainda não programei a aplicação, só testei esse exemplo e penso que é isto mesmo!!

Obrigado :)
 
Back
Topo