Thread: special function detection

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    4

    special function detection

    Hi. i need to do a console aplication in c that uses special function keys. But it seems that keys like (ctrl, alt, etc) are not being passed to the app. and the special function keys just write garbage onto the screen. Any guidelines? I'm programming under linux.
    i would also appreciate some advices about this for simple 16-bits console aplications for windows. once i did a program that used the special function keys but it was made in asm and i checked bios memory areas. i suposse there must be a way to detect this keys at some more upper level. For example when you press a f? key under DOS the system send two characters to the buffer the first one is 00 and the second is the key-code so you can use two getch() to detect the key. Something like that for the ctrl + ?
    thanks in advance

  2. #2
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    Hi

    If you just want to detect a control character "man iscntrl" will give you something.

    I am also looking for a UNIX function that can be used istead of DOS getch() (here is the thread http://cboard.cprogramming.com/showthread.php?t=76309 ).

    If you are using in ncurses there is a getch() function does the same thing as DOS version. You have to call noecho() if you don't want to display the character being typed.
    Last edited by fnoyan; 02-27-2006 at 04:39 AM.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    4
    there is a way to make a "getch" function in linux, i use something like this.
    Code:
    int getch() {
      int c;
      system(stty -echo);
      c = getchar();
      system(stty echo);
      return c;
    }
    hope it helps you;

  4. #4
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    Hi

    Thanks for the code but it just embeds getchar() into a function! So, it still requires an extra CR! This is not I actually want!

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    4
    ok. my fault, i hadn'r read your post. now i see

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I'm programming under linux.
    I would suggest you look at the ncurses package, which wraps the screen/keyboard in a slightly more capable interface.

    > i would also appreciate some advices about this for simple 16-bits console aplications for windows
    What are you using - turboC as your compiler?
    If your OS is NT/2K/XP, then your console is 32 bit.

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    4
    i know how to use ncurses but i don't see much use for the ncurses functionality in my project. just want to receive and process especial and control keys to perform some simple tasks not graphical ones.
    and i'm using TC under the old DOS. so indeed my application will be a 16-bit one.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    int getch() {
      int c;
      system(stty -echo);
      c = getchar();
      system(stty echo);
      return c;
    }
    I presume you meant to put quotes around system()s' arguments:
    Code:
    int getch() {
      int c;
      system("stty -echo");
      c = getchar();
      system("stty echo");
      return c;
    }
    and i'm using TC under the old DOS.
    WHY? I would use Dev-C++ if I were you.

    just want to receive and process especial and control keys to perform some simple tasks not graphical ones.
    There's an FAQ on the subject (or rather several) in order of usefulness:
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post your games here...
    By Hammer in forum Game Programming
    Replies: 132
    Last Post: 02-28-2013, 09:29 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM