User avatar
jwzumwalt
Posts: 44
Joined: Sun Aug 04, 2013 4:00 pm

Poll keyboard in "C"

Thu Nov 07, 2013 6:01 am

I need to be able to poll the keyboard in "C" without interrupting the program.
How would I do this?

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Poll keyboard in "C"

Thu Nov 07, 2013 6:05 am

You could try something like this. I have been using something similar here.

User avatar
jwzumwalt
Posts: 44
Joined: Sun Aug 04, 2013 4:00 pm

Re: Poll keyboard in "C"

Thu Nov 07, 2013 6:15 am

Thank you for your quick reply.

Any chance of you commenting the code you have on GIT?

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Poll keyboard in "C"

Thu Nov 07, 2013 6:19 am

jwzumwalt wrote:Any chance of you commenting the code you have on GIT?
Yes, there is a good chance. Probably wont happen until later tonight.

User avatar
AndyD
Posts: 2334
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Poll keyboard in "C"

Thu Nov 07, 2013 12:40 pm

jwzumwalt wrote:Any chance of you commenting the code you have on GIT?
OK I have commented the code in key.c and key.h.

Edit: Another option would be to use ncurses

User avatar
jwzumwalt
Posts: 44
Joined: Sun Aug 04, 2013 4:00 pm

Re: Poll keyboard in "C"

Thu Nov 07, 2013 5:22 pm

Thanks for the comments.

I forgot about ncurses.
I have never used it but several programmers I worked with wrote many terminal programs with it 25yrs ago.
Your code looks short and simple, I'll give it a try first.

Return to “C/C++”