Author Topic: kbhit C implementation for eCS GCC ?  (Read 1935 times)

agena@alex

  • Newbie
  • *
  • Thank You
  • -Given: 14
  • -Receive: 6
  • Posts: 36
    • View Profile
kbhit C implementation for eCS GCC ?
« on: September 08, 2014, 04:33:14 pm »
Hello,

yesterday, I searched for hours for an alternative C implementation of kbhit which checks whether
a key on the keyboard has been pressed, and which just returns a Boolean 0 or 1 but does not
write anything to stdout.

The eCS GCC conio header files unfortunately miss this non-ANSI C function.

Do you have a hint ? Thank you.

Alex




Sergey Posokhov

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 5
  • Posts: 104
    • View Profile
    • OS/2 API Research
Re: kbhit C implementation for eCS GCC ?
« Reply #1 on: September 08, 2014, 04:48:10 pm »
"KbdGetConsole()".

walking_x

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 6
  • Posts: 93
    • View Profile
Re: kbhit C implementation for eCS GCC ?
« Reply #2 on: September 08, 2014, 04:51:04 pm »
Just copy it from Open Watcom runtime (bld\clib\conio\c\kbhitos2.c).
It looks like only KbdPeek is required for console app:

Code: [Select]
_WCRTLINK int kbhit( void ){
    KBDKEYINFO  info;

    if( _RWD_cbyte != 0 )
        return( 1 );
#ifdef DEFAULT_WINDOWING
    if( _WindowsKbhit != 0 ) {      // Default windowing
        LPWDATA     res;
        res = _WindowsIsWindowedHandle( (int) STDIN_FILENO );
        return( _WindowsKbhit( res ) );
    }
#endif
#if defined(__OS2_286__)
    if( _RWD_osmode == DOS_MODE ) {
        return( _os_kbhit() );
    }
    KbdPeek( &info, 0 );
    return( ( info.fbStatus & 0xe0 ) != 0 );
#else
    KbdPeek( &info, 0 );
    return( ( info.fbStatus & 0xe0 ) != 0 );
#endif
}

agena@alex

  • Newbie
  • *
  • Thank You
  • -Given: 14
  • -Receive: 6
  • Posts: 36
    • View Profile
Re: kbhit C implementation for eCS GCC ?
« Reply #3 on: September 08, 2014, 04:57:47 pm »
Hello,

unfortunately, I found no `[Kk]bd*` functions in the header files of various GCC distributions.

Yes, I came across the Watcom OS/2 port.

I hoped that at least the i286 assembler code I found on the Watcom source distribution site could be compiled, but failed. Also, the Watcom licence somehow does not fit to the MIT licence, but I should check this again.

There is also a kbhit clone in the sources of the Harbour 3.0 language, but found them quite difficult to try.

Alex