kbhit in linux
i am literally exhuasted trying to hunt a better "kbhit" equivalent in linux. The first one i found was in FMOD api.. they provide a header called "wincompat.h" which implements the "kbhit." But unfortunatley that kbhit doesn't work so well.. it screws up at times. Then i did a bit of googling and found another implementation of "kbhit" but that too freezes my console.
Now where do i go from here... ? :S
Z
from a newsgroup posting by Andreas Kochenburger:
int WaitKey(void) /* return true when keyboard event is in queue */{#ifdef LINUX int i; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); tv.tv_sec = tv.tv_usec = 0; i = select(1, &fds, NULL, NULL, &tv); if (i == -1) return(MFALSE); if (FD_ISSET(STDIN_FILENO, &fds)) return(MTRUE); return(MFALSE); #else return(kbhit());#endif}
thanx, ur code seems to be working .. but consider the following code
once the getch is peformed the, the waitkey shouldn't return true unless a key is again pressed. But itz screwing at that point, the WaiKey still returning true.. ! By the way, i am using the getch fuction of curses.h so i am just wondering whether the getch of curses is conflicting with the custom WaitKey
while( 1 ){if(WaitKey()) getch();}
once the getch is peformed the, the waitkey shouldn't return true unless a key is again pressed. But itz screwing at that point, the WaiKey still returning true.. ! By the way, i am using the getch fuction of curses.h so i am just wondering whether the getch of curses is conflicting with the custom WaitKey
Z
What key did you pressed?
Perhaps I'm wrong (the last time I used these function was years ago) but with extended keys getch() may return a code and then another byte should be captured in order to know the very key. If this is the case, your custom kbhit() may read this second byte. But this could be under win... just an Idea...
Perhaps I'm wrong (the last time I used these function was years ago) but with extended keys getch() may return a code and then another byte should be captured in order to know the very key. If this is the case, your custom kbhit() may read this second byte. But this could be under win... just an Idea...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement