Automatic input?

Is it possible in C to code for an automatic input like if I enter the input 'A' I don't have to press the enter key to activate my input and it will automatically trigger the script. I've tried researching in search engines, I failed. I've tried different concepts and codes such as getche();. I really need it so that I can insert it to my project.

Note: I'm still a beginner, 1st year IT and this is my final project for the 1st sem.

btw can I upload an attachment here?
There's no standard way to do this. You can use getch or getche from conio.h or you can write you own getch function :


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
unsigned win_getch()
{
  char c=0;
  DWORD mode, count;
  HANDLE ih = GetStdHandle( STD_INPUT_HANDLE );

  if (!GetConsoleMode( ih, &mode )) // If this is a GUI program, or if GetConsoleMode() fails
      return 0;

  SetConsoleMode( ih, mode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT) ); // Disable echoing

  ReadConsoleA( ih, &c, 1, &count, NULL);

  SetConsoleMode( ih, mode ); // reset console to previous mode

  return c;
}



int main()
{
    char ch=win_getch();
    if(ch=='a' || ch=='A')
       cout <<"You pressed A";

}


btw can I upload an attachment here?

No.
Last edited on
Okay I'll try if it works.
just uninstall. No need to try, besides, this forum wont help you.
just uninstall. No need to try, besides, this forum wont help you.

What?
Last edited on
besides, this forum wont help you.


why? 'cuz its a c++ forum? There are a lot of members
who know C (and a lot of other languages :)
Topic archived. No new replies allowed.