Member Avatar for Chris11246

im trying to make a little game and i cant find how to use the keyboard to control it what does the code look like?

For windows application, set KeyPreview property of Form to True and handle key (KeyPress, KeyDown....) events.

Member Avatar for Chris11246

how do i choose which key

Set KeyPreview Property of Form1 at design time.

Public Class Form1
    Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.F1 Then
            MsgBox("F1 is pressed")
        Else
            If e.KeyCode = Keys.Escape Then
                MsgBox("Esc is pressed")
            End If
        End If
    End Sub
End Class
Member Avatar for Chris11246

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.