Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_CONSOLEINPUT is blocking
#6
Just as @DSMan195276 mentioned above, it's the used WINAPI function which blocks until at least one input event could be read. I've made the fix suggested by him and will push it for the next release.

However, if you cant wait, here's the fixed version of the C-Function, just look for it in internal\c\libqb.cpp and replace it.

Code: (Select All)
int32 func__getconsoleinput() {
#ifdef QB64_WINDOWS
    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
    INPUT_RECORD irInputRecord;
    DWORD dwEventsRead, fdwMode, dwMode;
    CONSOLE_SCREEN_BUFFER_INFO cl_bufinfo;

    GetConsoleMode(hStdin, (LPDWORD)&dwMode);
    fdwMode = ENABLE_EXTENDED_FLAGS;
    SetConsoleMode(hStdin, fdwMode);
    fdwMode = dwMode | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
    SetConsoleMode(hStdin, fdwMode);

    DWORD numEvents = 0;
    GetNumberOfConsoleInputEvents(hStdin, &numEvents);
    if (numEvents) {
        ReadConsoleInputA(hStdin, &irInputRecord, 1, &dwEventsRead);
        switch (irInputRecord.EventType) {
        case KEY_EVENT: // keyboard input
            consolekey = irInputRecord.Event.KeyEvent.wVirtualScanCode;
            if (!irInputRecord.Event.KeyEvent.bKeyDown)
                consolekey = -consolekey; // positive/negative return of scan codes.
            return 1;
        case MOUSE_EVENT: // mouse input
            consolemousex = irInputRecord.Event.MouseEvent.dwMousePosition.X + 1;
            consolemousey = irInputRecord.Event.MouseEvent.dwMousePosition.Y - cl_bufinfo.srWindow.Top + 1;
            consolebutton = irInputRecord.Event.MouseEvent.dwButtonState; // button state for all buttons
            // SetConsoleMode(hStdin, dwMode);
            return 2;
        }
    }
#endif
    return 0; // no or unhandled input
}

After that compile the following program and it should print "-" for no input, "M' for mouse input (Quick Edit mode must be off for mouse events (info added to the _CONSOLEINPUT Wiki page)) and the respective scan codes for keyboard input.

Code: (Select All)
$CONSOLE:ONLY

DO
_LIMIT 10
x%% = _CONSOLEINPUT
IF x%% = 1 THEN
k& = _CINP
PRINT k&;
ELSEIF x%% = 2 THEN
k& = 0
PRINT "M";
ELSE
k& = 0
PRINT "-";
END IF
LOOP
Reply


Messages In This Thread
RE: _CONSOLEINPUT is blocking - by RhoSigma - 7 hours ago



Users browsing this thread: 4 Guest(s)