I'm developing a game of C language snippet ( gcc 4.9.2 ) for the Ubuntu terminal 15.04 .
I need to capture a key typed by the user so he can change the direction in which the copper walks ( w
up, s
down, a
left, d
to the right).
For this, I'm using the following code snippet, inside a loop of repetition that moves the snake automatically while the user does not change the direction:
if(kbhit())
seta = getchar();
seta
is a variable of type char
that stores the key you typed.
The program does read correctly, however, it also writes on the screen the captured character, which obviously can not happen in such a game.
Are there any C functions that catch the key without typing the character on the screen or any equivalent procedure?
Obs : Although kbhit()
is a function originally from conio.h
, I was able to set it for Linux and it is working perfectly.