[mono-vb] Wait for key press

Rolf Bjarne Kvinge rolflists at ya.com
Wed Sep 8 05:43:54 EDT 2010


Hi,

I created a little test program, which works like you think it should (I
executed 'vbnc test.vb && mono test.exe').

If it still doesn't work for you, can you provide a complete sample I can
just compile and try to run?

Rolf


imports system
imports system.windows.forms
imports system.threading

public class F 
	inherits system.windows.forms.form
	dim Go as boolean
	
	Private Sub KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
		Console.WriteLine ("Keypress:  {0}", e.KeyCode)
		if e.KeyCode = Keys.T then Go = True
		if e.KeyCode = Keys.S then Exec
	end sub

	sub Exec
		Console.WriteLine ("Exec")
		Go = false
		Do
			Application.DoEvents()
			Threading.Thread.Sleep(1)
		Loop Until Go = True
		Console.WriteLine ("Exec [Done]")
	end sub
	
	shared sub Main
		Application.Run (new F ())
	end sub
end class



>-----Original Message-----
>From: mono-vb-bounces at lists.ximian.com [mailto:mono-vb-
>bounces at lists.ximian.com] On Behalf Of Yeek
>Sent: viernes, 03 de septiembre de 2010 20:48
>To: mono-vb at lists.ximian.com
>Subject: [mono-vb] Wait for key press
>
>
>Hi everyone
>
>I'm an intermediate programmer mainly working with VS 2008 using VB. I'm
>currently trying to port two of my projects to Mac OS X using Mono and
>MonoDevelop. During the ports I bumped into several issues that I was able
>to resolve. But now I'm struggling with a couple of lines that seem not to
>work with Mono (but do so with VB). What I would like to do is to continue
>code execution only after a certain key was pressed. I implemented the
>following lines in my main code:
>
>Go = false
>Do
>     Application.DoEvents()
>     Threading.Thread.Sleep(1)
>Loop Until Go = True
>
>
>And the global variable 'Go' is handled in the following sub:
>
>Private Sub KeyPress(ByVal sender As Object, ByVal e As
>System.Windows.KeyEventArgs) Handles Me.KeyUp
>     if e.KeyCode = Keys.T then Go = True
>end sub
>
>Using the lines above stops the execution of the code completely and key
>presses have no impact. Does anyone have an idea why this is the case and
>can maybe point me in the right direction on how to solve this issue?
>
>Any help is greatly appreciated. Thanks in advance!
>Martin
>
>
>
>--
>View this message in context: http://mono.1490590.n4.nabble.com/Wait-for-
>key-press-tp2526099p2526099.html
>Sent from the Mono - VB mailing list archive at Nabble.com.
>_______________________________________________
>Mono-vb mailing list
>Mono-vb at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-vb



More information about the Mono-vb mailing list