without windows functions, can i get the key state?

i'm using a loop for get a pressed key:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <string>

#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_LEFT 75
#define KEY_RIGHT 77
#define ESC 27

int main()
{
do
    {
        char ch;

        circle(x, y, 20);
        ch=getch();
        switch(ch)
        {
            case ESC:
                // your logic goes here
                break;
        }
    }while(1);
  return 0;
}


the problem is that the program waits until i press the key.
so, without using API functions, can i get the key state?
Last edited on
without using API functions

Which API(s)
The short answer is no.

C++ doesn't know what a key is. C++ has no concept of the keyboard. Even if it did, the OS is in charge of hardware so the OS moderates everything to do with hardware.

If you want to know something about the keyboard, you have to ask the OS about it. This can only be done through the OS API. Maybe you call the OS API, maybe you call some other function which calls the OS API, but however it's done, it goes through the OS.
ok... thanks for correct me
this looks like gaming stuff.
gaming stuff may prefer to use directinput or xinput or whatever it is called now to get real time keyboard controls. I believe you can simply at any time find out what the device is saying right now. This is different from getch because it can also give you the state of shift or alt or similar keys that getch cannot read.
Last edited on
Topic archived. No new replies allowed.