Étape 4: Un CODE SIMPLE VB
Public Class GamepadLauncher
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Si SerialPort1.IsOpen = faux alors
Si TextBox1.Text <> "« et TextBox2.Text <>" "puis
SerialPort1.PortName = TextBox1.Text
SerialPort1.BaudRate = TextBox2.Text
Si SerialPort1.IsOpen = faux alors
SerialPort1.Open()
MsgBox ("Serial ouvert »)
Timer1.Enabled = True
End If
D’autre
MsgBox ("port COM entrez et Baud Rate")
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Si SerialPort1.IsOpen = True Then
SerialPort1.Close()
Timer1.Enabled = False
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim a As String = ""
un = SerialPort1.ReadExisting
TextBox3.Text = TextBox3.Text + a
If a = « 1 » puis
SendKeys.Send("{up}")
Else if a = « 2 » puis SendKeys.Send("{down}")
Else if a = « 3 » puis SendKeys.Send("{left}")
Else if a = « 4 » puis SendKeys.Send("{right}")
End If
End Sub
End Class