Posts: 143
Threads: 14
Joined: Apr 2022
Reputation:
15
I can't find it in the documentation, but _CONSOLEINPUT seems blocking (waiting for a key) after the first call.
Code: (Select All)
$Console:Only
Do
x%% = _ConsoleInput
Print x%%;
Loop
Will only show one 0 and then waits for a keypress...
Is there any other way to check non-blocking for a key in a $CONSOLE window?
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Posts: 2,764
Threads: 334
Joined: Apr 2022
Reputation:
232
For a single keypress? Not usually. Why not create a normal program, hide the normal screen, use it to read the keystrokes via INKEY$ or _KEYHIT, and then process it on the visible CONSOLE if you need to do something like that?
Posts: 167
Threads: 12
Joined: Apr 2022
Reputation:
54
_CONSOLEINPUT is like _MOUSEINPUT, it just shows if new input is available and returns 1 for new keyboard input and 2 for new mouse input, however to retrieve the keyboard input use _CINP and for mouse the respective _MOUSExxx functions. _CONSOLEINPUT blocks until the actual input is retrieved, see example on the _CONSOLEINPUT and _CINP wiki pages.
Posts: 289
Threads: 6
Joined: Apr 2022
Reputation:
45
I'm with @mdijkens that this seems like a bug. We're currently calling `ReadConsoleInput` which blocks when there are no new events, we can call `GetNumberOfConsoleInputEvents` beforehand to check if it will block or not.
Posts: 143
Threads: 14
Joined: Apr 2022
Reputation:
15
(5 hours ago)RhoSigma Wrote: _CONSOLEINPUT is like _MOUSEINPUT, it just shows if new input is available and returns 1 for new keyboard input and 2 for new mouse input, however to retrieve the keyboard input use _CINP and for mouse the respective _MOUSExxx functions. _CONSOLEINPUT blocks until the actual input is retrieved, see example on the _CONSOLEINPUT and _CINP wiki pages.
Yes, I know, but the point is that it is blocking
Code: (Select All)
Do
_Limit 10
x%% = _ConsoleInput
If x%% = 1 Then
k& = _CInp
Print k&;
Else
k& = 0
Print "-";
End If
Loop
Here I would expect to see --------------------------- all the time except when pressing keys
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Posts: 143
Threads: 14
Joined: Apr 2022
Reputation:
15
That is great.
I am going to make that change.
Would be nice to have that in next version; waiting for input is easy enough if you still need that
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience