Menu

checking keyboard without waiting for key?

Anonymous
2002-03-29
2012-09-26
  • Anonymous

    Anonymous - 2002-03-29

    Sorry for this amount of questions!

    What I'm really trying to do is checking if the user has pressed a key without waiting for him to press a key. That's why I don't want to use the standard function "getc". If not necessary I would prefer not to use too much additional stuff like Windows API, ...
    Isn't there a way just using standard C libraries or DOS or BIOS functions?
    (I'm programing on and for a Windows98 System.)

    Thanks for answers!

     
    • Nobody/Anonymous

      >Isn't there a way just using standard C libraries or DOS or BIOS functions?

      No

       
    • Nobody/Anonymous

      Do you mean for console?
      <b>void</b> kbhit(<b>void</b>);
      will do the trick.
      It instantly checks for a key, which you can retrieve with <b>void</b> getch(<b>void</b>);
      They are in conio.h but for some reason you
      need to use conio_mingw.h with Dev-C++ and Mingw.

      This prog seems to work better when compiled with Borland  (and its conio.h)...

      Tom vC
      ------------------------------------

      #include <stdio.h>
      #include <conio_mingw.h>
      #include <time.h>

      main() {

        int keyhold, i = 0;
        clock_t start, end;
        double fps = CLK_TCK / 5;
        /* 5 is the frames per second */

        end = clock();

        /* loop runs for 10 seconds */
        for(i = 1; i < 50; i++) {
          start = clock();
          while( (end - start) / fps < 1) {
            if(kbhit() != 0) {
              keyhold = getch();
              putch(keyhold);
            }
          end = clock();
          }
          putch(1);
        }
        return(0);
      }

       
    • Nobody/Anonymous

      You might also want to #include <conio.c>
      to get full conio.h funcionality.

      Tom vC

      conio.<b>c</b>

      Yes, I know (now) HTML doesn't work here.
      I only glanced at the red text as the bottom.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.