From dePoPo.net

Detecting a keypress in a console application

Posted in: General vb.NET
By dePoPo
Sep 26, 2009 - 8:14:31 AM

The following code example runs a console application in a loop, until the escape key is pressed.



Module Module1

    Sub Main()

        Dim v_exitpointer As Boolean = False
        While v_exitpointer = False
            ' --- Main Programm




            ' --- Check to see if there is a console key pressed,
            '     and break the loop if it was escape
            If Console.KeyAvailable = True Then
                Dim mykey As ConsoleKeyInfo = Console.ReadKey
                If mykey.KeyChar = Chr(27) Then v_exitpointer = True
            End If

        End While

    End Sub

End Module

© Copyright 2010 by dePoPo.net