webJose wrote: |
---|
Furthermore, the function should start with WaitForSingleObject() to wait for the console input buffer to have something in it, making it unnecessary to return a boolean value because the call would be blocking and it would unlock only after reading input. |
If you don't know how getch() and kbhit() work together you should ask, and forgive me for not telling:
1 2 3 4 5 6 7 8 9 10
|
while (/*whatever*/) {
if (kbhit()) { // instantly returns if there's a key being pressed or not
ch1 = getch(); // returns the code for the first/last key in the keyboard buffer *
if (ch1 == 0) { // * blocks if buffer is empty
ch2 = getch();
}
}
// update a clock display, for example
// do stuff with certain keys
}
|
I need to be able to do stuff and wait for input at the same time. I can do that now, I just can't differentiate simple keys from complex keys;
But I'll try to see if your suggestion works.
andywestken wrote: |
---|
Why aren't you using getch() on Windows?
If you're interested in reimplementing getch as an exercise, fine. But you don't have to. |
Read first post. I want standardization. conio.h and dos.h is specific to Borland compilers and
hopefully other compilers, but not
all of them. windows.h, on the other hand, seems to be standard for all compilers, according to what I read.
EDIT: Sorry webJose, but your suggestion didn't worked. But it led me straight in the solution! With your suggestion I started wondering whether the INPUT_RECORD structure records stuff related to the keys or the keyboard buffer, so I went to MSDN to find out. It's the former, but more than that, I realized something: I was reading ASCII chars from keys, which would not return to me ASCII representations of special keys. But there's another member of INPUT_RECORD called wVirtualKeyCode that records the code for most keys on the keyboard plus some more stuff, devide-independent!
So now all I have to do is work with the defined constants instead of chars and I'll be good to go.
I guess I'll make my library available when I finish it so people can free themselves from conio.h and dos.h, although I just remembered that dos.h also contains functions to handle the buzzer which would be interesting to implement...
Thanks everyone and specially webJose for the help! Great forum this one.