Hi! This is the example code, I'm using these functions for a program, but scanf doesn't work well: It doesn't display my input and accepts the input only after the enter key is pressed twice.
this is the code:
#include <stdio.h>
#include <windows.h>
char c[25];
void KeyEventProc(KEY_EVENT_RECORD);
void KeyEventProc(KEY_EVENT_RECORD ker){
if(ker.bKeyDown) ; // do stuff
}
main(){
HANDLE hStdin;
DWORD cNumRead, fdwMode, fdwSaveOldMode, i;
INPUT_RECORD irInBuf[128];
hStdin = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hStdin, &fdwSaveOldMode);
fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
SetConsoleMode(hStdin, fdwMode);
ReadConsoleInput(hStdin, irInBuf, 128, &cNumRead);
for (i = 0; i < cNumRead; i++){
switch(irInBuf[i].EventType){
case KEY_EVENT:
KeyEventProc(irInBuf[i].Event.KeyEvent);
// do stuff
break;
default:
// do stuff
break;
}
}
scanf("%s", &c);
printf("%s", c);
}
thanks for help!