Paso 5: Código de teclas de Control
Ahora, reemplace el código de cada botón como sigue para controlar los movimientos
Avance:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If (lstPorts.SelectedIndex <> -1) Then SendSerialData(lstPorts.SelectedItem.ToString, "w") End If End Sub
Hacia atrás:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If (lstPorts.SelectedIndex <> -1) Then SendSerialData(lstPorts.SelectedItem.ToString, "s") End If End Sub
Izquierda:
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If (lstPorts.SelectedIndex <> -1) Then SendSerialData(lstPorts.SelectedItem.ToString, "a") End If End Sub
A la derecha:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click If (lstPorts.SelectedIndex <> -1) Then SendSerialData(lstPorts.SelectedItem.ToString, "d") End If End Sub
Parada:
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click If (lstPorts.SelectedIndex <> -1) Then SendSerialData(lstPorts.SelectedItem.ToString, "c") End If End Sub
Para cerrar el software debemos programar el botón dejar como sigue
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Application.Exit() If SerialPort.IsOpen Then SerialPort.Close() End If End Sub