0

Possible Duplicate:
How to read or capture Ctrl+some key or Alt+some key in C?

the code snippet :

char ks;
ks=getch(); // getting the keystroke : if non ascii then 2 bytes returned : 1st 0 then //scancode
if(ks==0) // if there's no ascii then get the scan code 
ks=getch();
printf("%d",ks); // would print ascii if ks !=0 else scan code 
//end

alt and control keys give no output while ctrl+e gives output as 5 . I dont get it , please explain .

Community
  • 1
  • 1
  • @melpomene it's a standard library function that returns a character from the standard input... –  Dec 22 '12 at 19:41
  • @melpomene Yes, it is. It's a deprecated POSIX-specific name for `getc()`. –  Dec 22 '12 at 19:44
  • @H2CO3 POSIX is not the standard C library. I'm very skeptical about `getch` being in POSIX. Do you have a citation? – melpomene Dec 22 '12 at 19:45
  • @melpomene The POSIX C library is part of the POSIX standard and is a superset of the ISO/ANSI C standard library. Citation? [This.](http://stackoverflow.com/questions/814975/getch-is-deprecated) –  Dec 22 '12 at 19:46
  • 1
    @H2CO3 Er. That's a Visual Studio error message (and it's lying). Quoting your own link: *Mentioning POSIX is what's wrong and misleading; this has nothing to do with POSIX. Moreover the function is not a standard function; it's a function name used by conio (and I believe also curses) for interactive single-character reads from the keyboard with no buffering.* – melpomene Dec 22 '12 at 19:50
  • @melpomene you can ask Google for one you like better... –  Dec 22 '12 at 19:51
  • 1
    http://stackoverflow.com/questions/9750588/how-to-get-ctrl-shift-or-alt-with-getch-ncurses – Per Johansson Dec 22 '12 at 21:36
  • Well there is a `getch()` in [X/Open Curses](http://pubs.opengroup.org/onlinepubs/7908799/xcurses/getch.html) but there _never_ was one in POSIX.1 – Greg A. Woods Dec 22 '12 at 21:41

1 Answers1

0

Ctrl, Alt, Shift are not characters and will not be found in the character stream to read.

Sunil Bojanapally
  • 12,528
  • 4
  • 33
  • 46