Keyboard checking

04 Feb 2010

Hi everyone,

Bit of an odd one here but i'm lloking for a way to check if NO key is being pressed. I know I can use getch() to get a key press but this is stumping me.

I would normally use kbhit(), but this is in the conio.h which isn't included?

Thanks in advance

Martin

04 Feb 2010

Hi Martin,

I presume you are using Serial or USB Serial. If so, try using readable(). It returns 1 if there is a character available to read, otherwise it returns 0. The Handbook PC Serial page contains an example.

Paul

05 Feb 2010

Thanks Paul, I must have missed that! I will give it a try.

05 Feb 2010

Hi Martin,

What kind of keyboard are you using?  A standard PC keyboard shouldn't work with USB Serial because it uses USB HID.

Anders

06 Feb 2010

Hi Anders.

Thanks for your reply. I am using a standard UK keyboard. I have solved the problem.

To keep the story short I kept getting a character appear on the screen when I didn't want it to. Thought I could sort it by checking there were no character waiting to be written, it didn't work.

Finally solved it by using fflush(connection) to wipe the buffer. 

Thanks for your help guys.

Martin