Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Southampton, England
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checking the keyboard buffer in Posix C?

    I'm programming in C on a Linux box and wondered if there was a way to check if the keyboard had been pressed, like kbhit but the Posix function?

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you could try this...I don't think its what you want but its really simple...

    if ((cin>>X) > "")

    that should work if X is declared as a string...


    Jason

  • #3
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Southampton, England
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anything in normal C, that looks like C++ to me.

    Thanks,

    Lloyd

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, wasn't thinking....

    String n;

    scanf( "%d", &n );

    I think thats right...I haven't used C in a while


    Jason

  • #5
    Regular Coder
    Join Date
    Feb 2003
    Location
    East Side/West Side
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually,

    char word[];

    and

    gets(word);


  • #6
    New to the CF scene
    Join Date
    Dec 2002
    Location
    Southampton, England
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Surely both of those methods block, i.e wait until the user has actually pressed the keyboard before the program can move on.

    What I want is a function like kbhit() (that isn't in POSIX C though), that I can poll regularly, e.g:

    while (1){

    updateScreenTime(); //arbitary function
    checkMP3Status();

    if (kbhit()) break; // need the POSIX function that works just
    //like kbhit()
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •