c++ - getch() to capture Ctrl-*letter* on linux -


i have decided use getch conio.h on linux. have heard not recommended need solution , work improve programming skills later.

i read number of tutorials of how enter one key , program something. such as:

printf("press key\n"); c = getch(); if (c)     printf(" key pressed keyboard "); else     printf("an error occurred "); 

however if want use enter ctrl+e print 'a ctrl held key'. how go around doing this?

getch() function found on windows in #include <conio.h> or on unix in #include <curses.h>. did mean call 1 of those? not function defined in c standard (the standard functions getc() , getchar(), of course). if use function <curses.h>, need initialization first , finalization afterwards.

assuming resolve issue of function planning call, find control characters number 1..26:

  • control-a = 1
  • control-z = 26

you might need translation work on getch() <curses.h> — it returns interesting values function keys , other special key strokes , might not return expect control keys.

also, terminal driver may confuse interpreting various characters (especially if use getchar() or getc()). example, control-d treated eof; control-h backspace or erase; control-c interrupt; , control-z 'suspend' (meaning 'return shell without exiting current program — suspend pro tem'). other control keys have other meanings. can 'genuine' meaning typing control-vcontrol-z, example — using control-v suppress special meaning of next character.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -