It always works with detecting click, but even if you don't use the mouse the keyboard input doesn't detect every keypress...anyone got an idea why this happens?
It is my understanding that _kbhit() is a function that asynchronously tells you if a key has been hit and it doesn't intend to be in synchrony with every single key press. In other words, you are not guaranteed to get one true for every key hit.
What you need is a different function, but don't ask me as I don't know which one. Google up a bit.
ReadConsoleInput() reads all selected console events, including key events. Your mouse code ignores all events not 'mouse'. Also, you are probably experiencing conflicts between the native API and the conio.h _getch() function.
What you should be doing is using ReadConsoleInput() in your main loop and switching off of the event type to the appropriate event handler.
I don't know what you mean by "cheap". It is very extensive and explicit.
Since you are trying to get unbuffered, no-echo input, you need to set the console input mode to not wait until the user presses ENTER to send input to the user. Also, you want to tell the console to give you mouse events.
Your startup code should look something like this:
1 2 3 4 5 6 7 8 9 10 11
HANDLE hInput = GetStdHandle( STD_INPUT_HANDLE );
DWORD original_console_mode;
if (!GetConsoleMode( hInput, &original_console_mode ))
{
cerr << "You must be a human to use this program.\n";
return 1;
}
SetConsoleMode( hInput, ENABLE_MOUSE_INPUT
// | ENABLE_PROCESSED_INPUT // Uncomment if you want the user to be able to press ^C to terminate
// | ENABLE_WINDOW_INPUT // Uncomment for window size events
);
Your cleanup code should look something like this: