Skip to content

Commit

Permalink
Merge pull request #598 from QB64-Phoenix-Edition/consoleinput-fix
Browse files Browse the repository at this point in the history
Fix _CONSOLEINPUT function
  • Loading branch information
RhoSigma-QB64 authored Jan 17, 2025
2 parents 0e33c30 + 1907a60 commit 2426d21
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions internal/c/libqb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31364,22 +31364,26 @@ int32 func__getconsoleinput() {
fdwMode = dwMode | ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
SetConsoleMode(hStdin, fdwMode);

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;
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; // in case it's some other odd input
return 0; // no or unhandled input
}

int32 func__cinp(int32 toggle, int32 passed) {
Expand Down

0 comments on commit 2426d21

Please sign in to comment.