console app read character?

I am making a console app and I would like to interact with it by getting a single keystroke from StdIn.
I cannot find any examples or documentation on how to read a keystroke without needing a Line Feed/CR.
Any ideas how to do this?

If you want your app to wait for the key, use StdIn.Read( 1 ). If you want to just check to see if anything has been typed, use StdIn.ReadAll.

StdIn.Read( 1 ) works but it seems to require the Return key to be pressed.
I want the app to respond to a single character entry. (no CR/LF)
I cannot figure out how to do this with StdIn.ReadAll.

It seems likely that the terminal does not send anything to StdIn until return is pressed. A quick Google search indicates that maybe the “stty raw” command can be used to change that behavior.

Hmm…
Is there any way (other than StdIn) to have the console app respond to a single keypress?

Works fine and as expected on macOS, but not on “Raspbian Pixel”…

None that I’ve found yet… so I’m looking forward to ideas, too :slight_smile:

BTW, I can confirm that Raspbian Pixel does not see the character, although the code does work on MacOS.

In

Function Run(args() as String) Handles Run as Integer
  ' =====Setup 
  print Chrb(27)+"c"
  print "Press 'q'  to quit." + endofline
  
  Dim key As String


  Do
    ' Looped code...

    key = StdIn.ReadAll
    App.DoEvents
    
  Loop until key = "q"
  
  
  ' ===== Shutdown
  print Chrb(27)+"c"
  print "Program ended successfully." + endofline
End Function