Keyboard input in c

Started by
3 comments, last by Armitage 23 years, 11 months ago
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?
A polar bear is a rectangular bear after a coordinate transform.
Advertisement
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
=======================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
A polar bear is a rectangular bear after a coordinate transform.
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

---[home page] [[email=karmalaa@inwind.it]e-mail[/email]]
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

This topic is closed to new replies.

Advertisement