Skip to content

Instantly share code, notes, and snippets.

@MattJeanes
Created October 8, 2013 18:59
Show Gist options
  • Save MattJeanes/6889743 to your computer and use it in GitHub Desktop.
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
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