Like Tree1Likes
  • 1 Post By twiki

NCURSES: Testing if a window has input instead of calling wgetch()

This is a discussion on NCURSES: Testing if a window has input instead of calling wgetch() within the Linux Programming forums, part of the Platform Specific Boards category; I'd just like to start by saying that ncurses/curses is one of the most finicky libraries I've ever dealt with... ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Some rock floating in space...
    Posts
    32

    Angry NCURSES: Testing if a window has input instead of calling wgetch()

    I'd just like to start by saying that ncurses/curses is one of the most finicky libraries I've ever dealt with... Everything has to be just right, or you get some funky results...

    I'm learning ncurses and I've run into some trouble...

    I have a main loop in my program which is waiting for wgetch(win) to return a value before continuing with the rest of my loop.

    e.g.
    Code:
    for(;;){
         ch = wgetch(my_window);
         switch(ch){
         /* key handling code here */
         }
        /* other stuff I need to do here
         * like updating time elapsed at top of screen */
        update_time();
       /* yada yada yada */
        
    }
    Anyway... My question is, does ncurses provide a function to test if a window has a key press waiting rather than wgetch() which waits for a key press?

    Or will I have to use timer_create to periodically update everything that can't wait, like timers etc.?


    Thanks in advance,

    Twiki

  2. #2
    Registered User
    Join Date
    Nov 2012
    Location
    Some rock floating in space...
    Posts
    32
    Quote Originally Posted by twiki View Post
    I'd just like to start by saying that ncurses/curses is one of the most finicky libraries I've ever dealt with... Everything has to be just right, or you get some funky results...

    I'm learning ncurses and I've run into some trouble...

    I have a main loop in my program which is waiting for wgetch(win) to return a value before continuing with the rest of my loop.

    e.g.
    Code:
    for(;;){
         ch = wgetch(my_window);
         switch(ch){
         /* key handling code here */
         }
        /* other stuff I need to do here
         * like updating time elapsed at top of screen */
        update_time();
       /* yada yada yada */
        
    }
    Anyway... My question is, does ncurses provide a function to test if a window has a key press waiting rather than wgetch() which waits for a key press?

    Or will I have to use timer_create to periodically update everything that can't wait, like timers etc.?


    Thanks in advance,

    Twiki
    Nevermind... I've answered my own question. It seems I have to call nodelay(my_win,TRUE) for the window in question so that wgetch(my_win) doesn't wait for input, but returns "ERR" instead of waiting for a key to be pressed. so in my switch statement, I need to include a case for the following

    Code:
     switch(ch){
       case 0:
       case ERR: break;  /* do nothing.. just break out of the switch statement */
    }
    Sorry to ask such a silly question, but I had been pouring over the docs and forums all around trying to find an alternative when one wasn't needed... just a simple flag set with nodelay(my_win,TRUE);
    Salem likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to clear ncurses window from (n, n) to (n, n)?
    By Ravi Raj in forum C Programming
    Replies: 5
    Last Post: 05-22-2012, 11:35 PM
  2. testing if input is a number
    By ecsx00 in forum C Programming
    Replies: 4
    Last Post: 11-11-2011, 01:15 AM
  3. Testing User Input
    By dolfaniss in forum C Programming
    Replies: 9
    Last Post: 02-15-2011, 12:27 PM
  4. ncurses window problem
    By fronty in forum Linux Programming
    Replies: 3
    Last Post: 09-22-2007, 09:33 AM
  5. Ncurses and WINDOW scrolling
    By birkoss in forum Linux Programming
    Replies: 0
    Last Post: 05-17-2002, 11:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21