Hey there, Interesting project you have here :) Must be a lot of fun to work on. I see this post was from a week back, so likely you have already figured this out for yourself, but for what it's worth I'll reply. I added a few remarks/comments to your code; I'm not going to nitpick on the finer details, as most of the code looks good! I did notice that you are using the Select Case in an odd way and it's probably best to just make an If-Then-ElseIf statement of it.
Jose Sallamanca wrote:
Anyway, the thing is working, and sending packets only on initial press or release of key(s). The one glitch I've so far detected is that when releasing all the keys, which should send the "z" character and stop the car, the same character that was previously sent is re-sent, rather than the 'stop' character "z".
So here's the code, VB 2008:
Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
Tmr.Stop()
' You don't need to stop the timer and then restart it. Just let it continue running (or did you find a specific need to restart it?)
If Not controlChoice = controlChoicePrev Then
'UDP_______________________________________________________
' I see here that you are constantly (every timer tick!) rebinding the udpClient to the target. Luckily, it's UDP so this is not disastrous, but it is
' a bit unnecessary. It's probably a better idea to relocate the GLOIP = .. GLOINTPORT = .. udpClient.Connect(..) to your Form1_Load event handler.
' Also, see my comment 1) at the end for a cautionary tip, which applies when you are running a 32 bits program under 64 bits windows.
' === BLOCK 1 ===
Try
' ------- START of the MOVE (when moved, enclose both in Try-Catch and handle the errors appropriately) -------
GLOIP = IPAddress.Parse("192.168.1.177")
GLOINTPORT = 8888
udpClient.Connect(GLOIP, GLOINTPORT)
' ------- END of the MOVE -------
bytCommand = Encoding.ASCII.GetBytes(cc)
udpClient.Send(bytCommand, bytCommand.Length)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
'UDP_______________________________________________________
End If
' === END BLOCK 1 ===
' === BLOCK 2 ===
If GetAsyncKeyState(Keys.Up) Or