1

I am developing a C application using ncurses library in linux. my program cant distinguish between Alt and Esc keypresses. both return 27! can you help me how I can distinguish between the two? thank you

rahman
  • 4,820
  • 16
  • 52
  • 86

2 Answers2

2

You need to incorporate a short delay after the ^[ in order to see if there are further characters incoming. If not, then Esc has been pressed.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • I don't know how to do that! do u mean using sleep/usleep ? could you kindly provide an example? – rahman Jun 29 '11 at 07:53
1

Take a look here:

NCurses and ESC,ALT keys

Can't try it right now, though. Hope it helps.

Community
  • 1
  • 1
mahju
  • 1,156
  • 1
  • 14
  • 21
  • I had already seen that. But didn't know what ERR means. could you please provide an example for me? thanks (i think even without using ncurses u can provide an example. am i right?) thanks again – rahman Jun 29 '11 at 07:56
  • 2
    ncurses timeout does the job very well. timeout(1); ch=getch(); if(ch=='d') {...} thank you all – rahman Aug 03 '11 at 10:36