Created
October 8, 2013 18:59
-
-
Save MattJeanes/6889743 to your computer and use it in GitHub Desktop.
Example of console.readkey usage to read an authorisation code without the need to press enter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Module Module1 | |
Function GetString(ByVal InputS As String) As String | |
Dim TempS As String = "" | |
Dim TempC As ConsoleKeyInfo | |
Do | |
TempC = Console.ReadKey() | |
If TempC.Key = ConsoleKey.Escape Or TempC.Key = ConsoleKey.Enter Then | |
Console.Write(vbNewLine) | |
Return False | |
Else | |
TempS += TempC.KeyChar | |
End If | |
If TempS = InputS Then | |
Console.Write(vbNewLine) | |
Return True | |
End If | |
Loop | |
End Function | |
Sub Main() | |
Console.WriteLine("Please enter the auth code:") | |
If GetString("1234") Then | |
Console.WriteLine("You win!") | |
Else | |
Console.WriteLine("You failed.") | |
End If | |
Console.WriteLine("Press any key to exit..") | |
Console.ReadKey() | |
End Sub | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment