I recently read an answer from this question where basicly everything gets resolved.
The answer was this. I implemented it into my code base and everything seemed to work. But when using the KEY_EVENT
it only works when other keys are not pressed.
With that i mean when i press 'a' everything works fine, but when i use 'SHIFT+A' it doesnt work anymore.
I downloaded the demo project that he attached in the answer and this were the results i got.
The second result also applies to any other button combination. I can use CTRL or ALT and the result looks always exactly the same like the second picture. The only thing that changes is wVirtualKeyCode
(Shift=16, Ctrl=17, Alt=18)
Does maybe someone have an answer why the key combinations wont work?
Here is the Start Method which does all the reading.
public static void Start()
{
if (!Run)
{
Run = true;
IntPtr handleIn = GetStdHandle(STD_INPUT_HANDLE);
new Thread(() =>
{
while (true)
{
uint numRead = 0;
INPUT_RECORD[] record = new INPUT_RECORD[1];
record[0] = new INPUT_RECORD();
ReadConsoleInput(handleIn, record, 1, ref numRead);
if (Run)
switch (record[0].EventType)
{
case INPUT_RECORD.MOUSE_EVENT:
MouseEvent?.Invoke(record[0].MouseEvent);
break;
case INPUT_RECORD.KEY_EVENT:
KeyEvent?.Invoke(record[0].KeyEvent);
break;
case INPUT_RECORD.WINDOW_BUFFER_SIZE_EVENT:
WindowBufferSizeEvent?.Invoke(record[0].WindowBufferSizeEvent);
break;
}
else
{
uint numWritten = 0;
WriteConsoleInput(handleIn, record, 1, ref numWritten);
return;
}
}
}).Start();
}
}