vb.net do while spacebar held down

Associate
Joined
23 Oct 2004
Posts
2,441
Location
Brighton
Howdy,

vb.net

Inside a Sub I want to only execute some code when the spacebar is held down.

Googled, but no joy. Any ideas?

Cheers.
 
I'm not a VB.NET programmer but in general programming terms I would think you need to do the following:

1. Detect a "key down" event

2. If the key pressed was space enter a while loop, if not continue

3. Execute whatever code you want in the while loop

4. Inside the while loop wait for a "key up" event

5. If the key released was space, exit the while loop, if not continue in the loop
 
Got it sussed. There is a sneaky KeyPresses setting on the main form that needed enabling.

Private Sub mouseCapture_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Space Then
moutput = 1
m_serialmon.Text = "Serial On"
m_sendingserial.BackColor = Color.Green
End If
End Sub
Private Sub mouseCapture_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Space Then
moutput = 0
m_serialmon.Text = "Serial Off"
m_sendingserial.BackColor = Color.Firebrick
End If
End Sub
 
Yup.

It is a 12 channel servo controller with 3 switchable outputs and record memory. Just cobbling together a controller in VB to talk to the firmware.
 
Sounds cool, I've recently been playing with Arduino communications over serial using Java and Processing.org (a reduced abstraction of Java that is easier to use).
 
Back
Top Bottom