kbhit.h

  • Katushai
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152

Post 3+ Months Ago

Does anybody know where i can get kbhit.h for linux, with getch() in it?
  • Daemonguy
  • Moderator
  • Web Master
  • User avatar
  • Posts: 2700
  • Loc: Somewhere outside the box in Sarasota, FL.

Post 3+ Months Ago

Found some of this some time ago, finished it off.

Enjoy.
YMMV.

Code: [ Select ]
* kbhit.h */

#include

int kbhit(void)
{
struct timeval tv;
fd_set read_fd;

tv.tv_sec=0;
tv.tv_usec=0;
FD_ZERO(&read_fd);
FD_SET(0,&read_fd);

if(select(1, &read_fd, NULL, NULL, &tv) == -1)
return 0;

if(FD_ISSET(0,&read_fd))
return 1;

return 0;
}
  1. * kbhit.h */
  2. #include
  3. int kbhit(void)
  4. {
  5. struct timeval tv;
  6. fd_set read_fd;
  7. tv.tv_sec=0;
  8. tv.tv_usec=0;
  9. FD_ZERO(&read_fd);
  10. FD_SET(0,&read_fd);
  11. if(select(1, &read_fd, NULL, NULL, &tv) == -1)
  12. return 0;
  13. if(FD_ISSET(0,&read_fd))
  14. return 1;
  15. return 0;
  16. }


Include it and the kbhit() thusly;

Code: [ Select ]
#include
#include "kbhit.h"

int main()
{
printf("hello\n");
printf("Press any key to continue..\n");
while(!kbhit());
printf("bye bye\n");

return 0;
}
  1. #include
  2. #include "kbhit.h"
  3. int main()
  4. {
  5. printf("hello\n");
  6. printf("Press any key to continue..\n");
  7. while(!kbhit());
  8. printf("bye bye\n");
  9. return 0;
  10. }


Cheers.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.