Keyboard input in c
Hi. I''ve gotten the totally exciting assignment to code the game "snake" in c/ascii. I grew up with c++, I might add. The problem is, I don''t know how to check the keyboard for input without using assembler (or c++). Is it possible? The best thing I''ve found is ch = getch() which is unbuffered, but it sits around and waits, and I''m afraid I can''t let it do that.
Is it even possible in "pure" c?
It IS possible! (whoa!)
if(kbhit()) inp=getch();
This will check if there is a key in the buffer, and then take it with getch(); it works, it''s slow, but it works.
and you have to zero inp at the begining of each loop...
========================
Game project(s):
www.fiend.cjb.net
if(kbhit()) inp=getch();
This will check if there is a key in the buffer, and then take it with getch(); it works, it''s slow, but it works.
and you have to zero inp at the begining of each loop...
========================
Game project(s):
www.fiend.cjb.net
Thanks. I tried that one first, but it didn''t seem to work. Did the other time around, though
quote:Original post by JonatanHedborg
It IS possible! (whoa!)
if(kbhit()) inp=getch();
This will check if there is a key in the buffer, and then take it with getch(); it works, it''s slow, but it works.
and you have to zero inp at the begining of each loop...
Umm... this does work only under DOS-oriented applications and so is not very portable (nor ANSI compliant).
Bye,
Karmalaa
Sorry, but i don''t think you can do it in "pure" ANSI C. You''ll have tu use OS dependant functions.
Prosper / LOADED corporation
Prosper / LOADED corporation
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement