ron@clarity.Princeton.EDU (Ronald Beekelaar) (02/05/90)
Hi, I left out some needed information in my question last night. I was wondering whether I can silently test whether a key has been pressed in C, without having to read(..). I forgot to tell that I am using MS-C on an IBM-PC. I would help me enormously, if somebody could tell me how I should do this. Thanks, -- ------ ron ------
brianh@hpcvia.CV.HP.COM (brian_helterline) (02/06/90)
ron@clarity.Princeton.EDU (Ronald Beekelaar) writes: >Hi, > I left out some needed information in my question last night. >I was wondering whether I can silently test whether a key has been pressed in >C, without having to read(..). I forgot to tell that I am using MS-C on an >IBM-PC. > I would help me enormously, if somebody could tell me how I should do this. >Thanks, >-- >------ >ron >------ >---------- unsigned status; status = _bios_keybrd( _KEYBRD_READY ); if( status == 0 ) /* no key pressed */ else /* some key was pressed */ If you are concerned about the SHIFT, CTRL, ALT, SCROLL LOCK, NUM LOCK, CAPS LOCK, and INSERT use _bios_keybrd( _KEYBRD_SHIFTSTATUS ) with the above. -------- OR --------------- You can use the function int kbhit(void) to check if a key has been pressed but not the SHIFT, CTRL, ALT, ....
fredex@cg-atla.UUCP (Fred Smith) (02/07/90)
In article <RON.90Feb4114158@clarity.Princeton.EDU> ron@clarity.Princeton.EDU (Ronald Beekelaar) writes: >Hi, > > I left out some needed information in my question last night. >I was wondering whether I can silently test whether a key has been pressed in >C, without having to read(..). I forgot to tell that I am using MS-C on an >IBM-PC. > Yes. You should read the section in your MSC manual about the routine named "_bios_keybrd()". If you find that not to your liking, try "kbhit()" (which, you should be warned, will give bogus results if you happen to redirect stdin to your program).. Fred