bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

X and ncurses / getch() and X-keyevents


From: Thomas Zauner
Subject: X and ncurses / getch() and X-keyevents
Date: 15 Feb 2003 19:58:33 +0100

hello,

i use ncurses within an xterm.
there are some thing i dont understand.

all given code is pseudo-c. it should be obvious what is meant.



1) when resizing the xterm i get a keycode 410 returned from getch()
is that the "official" way to handl window resizes?

---------------------------------------------
int key=0;
int main(){
  
  initscr(); 
  noecho();
  raw();

  while(){
   key=getch();
   printf(key); 
  }; 

  endwin(); 
};
----------------------------------------------------------



2) i use sth. like the following to handle events. 
most of the time it works fine but sometimes the getch() dosen't get the right 
key or a key at all when i press it. 
i think its the combination of the X event loop and the getch() function but i 
cant figure out why it's "wrong" or "poor" code. 
OK here we go
--------------------------------------------------------------------------- 


Display *display;
Window win;
int row=0,col=0;                         
XWindowAttributes atr;
XEvent event;
char *win_id;
bool done=false;
int key=0;
int events=0;  //pending events in the x queue


// !!  xdmesg() IS JUST  MY FUNC TO PUT TEXT TO THE XCONSOLE AND DO    // SOME 
ERR. CHECKS 

int main(){

  initscr(); 
  keypad(stdscr,TRUE);
  noecho();
  raw();
  

  XSelectInput(display,win,ExposureMask | KeyPressMask |StructureNotifyMask);

  while(!done){
    events=XEventsQueued(display,QueuedAfterFlush);

    
    if(events != 0 ){

      XNextEvent(display,&event);
      switch(event.type){

      case Expose:
        xdmsg("Expose");
        break;
     
      case ConfigureNotify:
        xdmsg("Resize");
        break;

      case KeyPress:
         key=getch();
         xdmsg("keypreessed: %d" , key);
         if(key == 113){   /* "q" key */
           xdmsg("quit pressed exiting");
           done=true;
           };
         break;
      };
      }; 
    
  //usleep(10);  to cut down cpu load for testing other stuff
};


  endwin();
  XCloseDisplay(display);
  return 0;
};

----------------------------------------------------------------------------------------------------




thx,
tom





reply via email to

[Prev in Thread] Current Thread [Next in Thread]