Character reading problem!!

I have a loop in my code, something like this:

while(1)
{

char c=getc();

Sleep(50);

run_next_animation_frame();
}

I need animation to run, no matter - was the key pressed or it wasn't.
Also - I have to check if user have pressed some key and get the key code if he did.

getc waits for user to input something - therefore stops the animation. I have already done something like this once, but I've forgoten which function I used back there.

Please help!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "stdafx.h"

int key_ctrl = GetKeyState(17);
int key_shift = GetKeyState(16);
int key_kp_plus = GetKeyState(107);
int key_kp_minus = GetKeyState(109);
int key_e = GetKeyState(69);
int key_t = GetKeyState(84);
int key_r = GetKeyState(82);

if(key_ctrl == -128 || key_ctrl == -127) {
    // CTRL is pressed
} else {
    // otherwise it's not
}

// etc. 


I believe the key constants start with VK_ or so. Type it and do CTRL + Spacebar in MSVC to see what starts with that.
this isn't quite what i expected. there should be a simple function to do it.
If you use the old conio.h library you could do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
char c;
while(1)
{

    if (kbhit()) //checks if there is data in the input buffer
    {
        c=getchar();
        //do something with c...
    }

Sleep(50);

run_next_animation_frame();
}
Last edited on
thanks!
Topic archived. No new replies allowed.