0

I am using C and I am trying to write a small game. But I need to read the input whenever the player tabs on a key (say s), and the program does something, without pressing the enter.

I have seen many posts answering this, but they all use getchar() or getch() from curses or conio.h in Windows. But that's not what I want. The result can definitely done because of 2 examples:

  1. vim when the user tabs on the :, it will immediately turns into the command mode to let you type in the commands.
  2. the readcommand in bash, whose -n${number_you_want} parameter can limit the chars it reads without enter.

But I wonder how they can do this even I already have the source of the functions in the examples. I still can't figure out how they do this. The source code of vim's inchar() from getchar.c and the read command from bash source read.def.

Can anyone help me explain how they works? Thanks in advance.

Chromium
  • 517
  • 1
  • 6
  • 21
  • But that answer post is using C++, and the `read` command and `vim` don't use the `conio.h` and the `getch()` function though I can give it a try. – Chromium Feb 04 '16 at 06:10
  • And I am using Linux instead of Windows, so no such `conio.h`. – Chromium Feb 04 '16 at 06:11

0 Answers0