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?
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.
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.
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 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.
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).