-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mouse doesn't work #85
mouse doesn't work #85
Comments
@Fredloire, I haven't heard of this. I've filed MSFT: 20740022 in our internal bug tracker to try to figure out if this is intentional and needs to be documented or if it was unintentional and therefore a bug that needs to be fixed. |
I hope it's unintentional... The console is very educational for computer students and I personally like this universe that reminds of the first hours of computing and fits perfectly into the art ascii. |
The program doesn't detect mouse events, because ENABLE_QUICK_MODE is enabled. I had the same problem and disabling the mode actually helped. |
Thank you so much. I just tested with ENABLE_EXTENDED_FLAGS disabled. I get the coordinates of the mouse very well but the clicks are not insured. Clicks only occasionally work. Sometimes they still cause a selection at the clicked place. I used : Maybe another flag is missing? But which one? Do you have an idea ? |
You're welcome ;v. So in my opinion it's impossible to selection (and handling mouse events) sometimes work and sometimes not. Most likely you have just missed something in your code and the ENABLE_QUICK_EDIT_MODE still gets enabled and disabled. P.S. I'm still a bit fresh in windows API and I might miss something ;v By the way here is the code from the article modified by me that works: #include <windows.h>
#include <stdio.h>
HANDLE hStdin;
DWORD fdwSaveOldMode;
VOID ErrorExit(LPCSTR lpszMessage);
VOID KeyEventProc(KEY_EVENT_RECORD);
VOID MouseEventProc(MOUSE_EVENT_RECORD);
VOID ResizeEventProc(WINDOW_BUFFER_SIZE_RECORD);
int main(VOID)
{
DWORD cNumRead, fdwMode, i;
INPUT_RECORD irInBuf[128];
int counter = 0;
// Get the standard input handle.
hStdin = GetStdHandle(STD_INPUT_HANDLE);
if (hStdin == INVALID_HANDLE_VALUE)
ErrorExit("GetStdHandle");
// Save the current input mode, to be restored on exit.
if (!GetConsoleMode(hStdin, &fdwSaveOldMode))
ErrorExit("GetConsoleMode");
// Enable the window and mouse input events.
fdwMode = (/*ENABLE_WINDOW_INPUT |*/ ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS) & ~(ENABLE_QUICK_EDIT_MODE /*| ENABLE_WINDOW_INPUT*/);
// ^I don't know why, but the program recognizes the window events even if the flag is disabled
// ENABLE_EXTENDED_FLAGS has to be enabled, because we want to DISABLE ENABLE_QUICK_EDIT_MODE
if (!SetConsoleMode(hStdin, fdwMode))
ErrorExit("SetConsoleMode");
// Loop to read and handle the next 100 input events.
while (true)
{
// Wait for the events.
if (!ReadConsoleInput(
hStdin, // input buffer handle
irInBuf, // buffer to read into
128, // size of read buffer
&cNumRead)) // number of records read
ErrorExit("ReadConsoleInput");
// Dispatch the events to the appropriate handler.
for (i = 0; i < cNumRead; i++)
{
switch (irInBuf[i].EventType)
{
case KEY_EVENT: // keyboard input
KeyEventProc(irInBuf[i].Event.KeyEvent);
break;
case MOUSE_EVENT: // mouse input
MouseEventProc(irInBuf[i].Event.MouseEvent);
break;
case WINDOW_BUFFER_SIZE_EVENT: // scrn buf. resizing
ResizeEventProc(irInBuf[i].Event.WindowBufferSizeEvent);
break;
case FOCUS_EVENT: // disregard focus events
case MENU_EVENT: // disregard menu events
break;
default:
ErrorExit("Unknown event type");
break;
}
}
}
// Restore input mode on exit.
SetConsoleMode(hStdin, fdwSaveOldMode);
return 0;
}
VOID ErrorExit(LPCSTR lpszMessage)
{
fprintf(stderr, "%s\n", lpszMessage);
// Restore input mode on exit.
SetConsoleMode(hStdin, fdwSaveOldMode);
ExitProcess(0);
}
VOID KeyEventProc(KEY_EVENT_RECORD ker)
{
printf("Key event: ");
if (ker.bKeyDown)
printf("key pressed\n");
else printf("key released\n");
}
VOID MouseEventProc(MOUSE_EVENT_RECORD mer)
{
#ifndef MOUSE_HWHEELED
#define MOUSE_HWHEELED 0x0008
#endif
printf("Mouse event: ");
switch (mer.dwEventFlags)
{
case 0:
if (mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
{
printf("left button press \n");
}
else if (mer.dwButtonState == RIGHTMOST_BUTTON_PRESSED)
{
printf("right button press \n");
}
else
{
printf("button press\n");
}
break;
case DOUBLE_CLICK:
printf("double click\n");
break;
case MOUSE_HWHEELED:
printf("horizontal mouse wheel\n");
break;
case MOUSE_MOVED:
POINT pPoint;
GetCursorPos(&pPoint);
printf("mouse moved, it's position: x=%d, y=%d\n", pPoint.x, pPoint.y);
break;
case MOUSE_WHEELED:
printf("vertical mouse wheel\n");
break;
default:
printf("unknown\n");
break;
}
}
VOID ResizeEventProc(WINDOW_BUFFER_SIZE_RECORD wbsr)
{
printf("Resize event\n");
printf("Console screen buffer is %d columns by %d rows.\n", wbsr.dwSize.X, wbsr.dwSize.Y);
} |
It works ! Thanks to that I could find another error, personal, that I had made in my code. Thank you very much and long live the console! |
Closing as it looks like you solved it. |
Hello,
I am currently working using the console. I need the mouse. The example with ReadConsoleInput does not work for the mouse since the update 1809 of windows 10 (it worked before). Do you have an idea of why? Is there a solution ?
Thank you so much.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: