special function detection

This is a discussion on special function detection within the C Programming forums, part of the General Programming Boards category; Hi. i need to do a console aplication in c that uses special function keys. But it seems that keys ...

  1. #1
    zyd
    zyd is offline
    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
    269
    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 ,getting the key without ENTERing ).

    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 03:39 AM.

  3. #3
    zyd
    zyd is offline
    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
    269
    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
    zyd
    zyd is offline
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    > 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
    zyd
    zyd is offline
    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,045
    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, 08: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, 12:03 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21