console application question >.<?

ok i am trying to make a simple game on the console application so i made something as simple as if i press 'A' on my keyboard it tells me that i pressed
the letter 'A' here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

int main(){
    char input;
    cin>>input;
    if (input=='a'){
                  cout<< "you pressed 'a' on the keyboard! XD" <<endl;
                  cin.get();
                  }
                  else {
                       cout<< "you did not press a" <<endl;
                       cin.get();
                       }
                       cin.get();
                       }


ok but in order to make it work i still have to press Enter after i press 'A'
how do i cancel the Enter button (so i can just press 'A' instead >.>? is
there a way?
Last edited on
Try searching for something like 'unbuffered input'.
ahh thank you for the link very helpful XD
ok 1 more question these dlls that im gonna use to get keyboard input corectly
were made with C++ so just for the sake of knowing it (so maybe i could make my own dlls)

so how would i get keyboard input >.>?
closed account (zwA4jE8b)
#include conio.h

1
2
3
4
if(kbhit())
 char = getch();
   if(char == 'h')
     cprintf("You pressed H");


and here comes the why conio.h is no good.... GO

btw char = some char variable
Last edited on
:-)

For a simple, education console program on Windows, I am very much pro getch, though I think it perfersto be called _getch these days.

Apart from anything else, it keeps the dependencies down (no need to include windows.h)
Last edited on
thanks peoples ill mess around with this information to see what works best XD
Topic archived. No new replies allowed.