5
I’m developing a C-language cover game (gcc 4.9.2) to the Ubuntu terminal 15.04.
I need to capture a key typed by the user so that he can change the direction in which the topsail anda (w
upward, s
down, a
to the left, d
right).
For this, I am using the following code snippet, inside a loop that moves the cover automatically while the user does not change the direction:
if(kbhit())
seta = getchar();
seta
is a variable of the type char
which stores the typed key.
The program does the reading correctly, however, it also writes on the screen the captured character, which obviously cannot happen in a game of this type.
Are there any C function that captures the key without writing the character on the screen or any equivalent procedure?
Obs.: Although kbhit()
is originally a function of conio.h
, managed to set it to Linux and is working perfectly.
@Joãopedro That would be http://stackoverflow.com/a/7469410/3257568 ?
– Maicon Carraro
@Joãopedro How you implemented kbhit?
– Maicon Carraro
I mean the code inside kbhit, you said you implemented, no?
– Maicon Carraro
@Joãopedro Take a look at this function
set_disp_mode
implements it and calls it with value0
before the getchar()– Maicon Carraro
@Joãopedro I updated my answer
– Maicon Carraro
you have some getchar before the while?
– Maicon Carraro
Quiet then, I’m glad you solved :)
– Maicon Carraro
If possible mark as the right answer, thank you!
– Maicon Carraro