Console with keyboard input?

I’m playing around with a console (Windows), trying to get keyboard input into it for simple things like showing stats etc. but I’m having some issues I was hoping someone else has solved already.

I thread out my loop for keyboard handling so that it doesnt impact/pause the main loop.

The documentation for Input says that “Input is equivalent to a call to the ReadLine method of the StandardInputStream class.”

However, if I use Input it blocks all processing even in threads spawned before calling Input, where as if I use stdin.ReadLine I dont have this issue.

Has anyone found this issue before?
How have you got around it?
Does anyone know why does the “equivalent” call does not have equivalent functionality?

I guess I’m looking for a crossplatform ReadConsoleInput

What I’m trying to get at is a keyboard routine that will no block, allow threads to run and not pause the shutdown of the program (or thread) by waiting for one last Enter to be sent to the console, while also allowing scrollback history using up arrow (I can let this slip).

I’ve tried Input, that blocks threads, I’ve tried stdin.ReadLine and stdin.Read, those wait for one last Enter before allowing code execution to continue, I’ve tried stdin.ReadAll, that doesn’t seem to read keyboard input (at least in Windows) and commands are sent to the cmd window after execution completes.

Use the Keyboard module ?

Keyboard isnt available in console applications

I’ll give StdinMBS a try, seems it has IsReady to check if input is waiting before reading.

Hmm, its not implemented on Windows.

Why not create a windowless desktop program instead ? I think MBS has the necessary plugin to provide Stdin and Stdout. At least they do under macOS.

I need to be able to run it as a console app on linux (without a UI) and windows. I just seems massively convoluted to have to write two programs, one to do what I want, and one to act as the interface.

I’ve tried the MSB plugin for std, but its IsReady which I need to use isnt support on Windows.

As is the norm for me I get 95% of the way to doing something that I need only to be thwarted at the last hurdle.

I’ll see if Christian can provide some feedback on the IsReady, if not I’ll have to use my own declares into some windows functions to get the functionality I need, and use MBS Util for MacOS & Linux.

Doh, just found feedback://showreport?report_id=1076 from 2008

I guess that wont be fixed any time soon :frowning:

Seems possible to have two console programs : the main program, and a helper dedicated to keyboard input. Then use http://documentation.xojo.com/index.php/IPCSocket to have them talk to each other.

BTW, I believe Input may be conformant to what I used way back when in QuickBasic : it did halt execution the very same way.

WindowsConsoleMBS maybe?
I could of course add something there.

[quote=321327:@Christian Schmitz]WindowsConsoleMBS maybe?
I could of course add something there.[/quote]

Hmm, I guess I could use WaitForReturn for Windows and StdinMBS for MacOS/Linux.

Could you add Windows support to StdinMBS.IsReady by using PeekConsoleInput for a KEY_EVENT_RECORD? (as per my email)

That would then make StdinMBS nice and cross platform and a one stop shop solution for this problem.

As I told you WindowsConsoleMBS is the way we use on windows to access console window.
StdInMBS is the unix way which partly works on Windows.

I don’t think I can mix those.

Ok thanks.

WindowsConsoleMBS is unfortunately no use to me, I need to use the Console window that is used to run the program, not spawn another one. I shall keep on reading/looking.

Did you find a solution for this Julian ?

I couldn’t remember writing the above, or the code related to this (my memory is slowly failing). I had to search my code base to see where I used any of the above and I found some test code.

It looks like I ended up using StandardInputStream.ReadLine in its own thread which doesn’t seem to block and doesn’t leave an app waiting for a final keypress when everything is shutting down (at least in windows it doesn’t).

1 Like

Thanks Julian.
I decided to add a UDPSocket, this way I could have a local “command line” helper app and also a remote graphical GUI if i want that.