Thread: Picking up keyboard input

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    11

    Picking up keyboard input

    Hey,

    So I've got this program that I'm writing that controls various things happening on screen. Nothing fancy, just an ascii interface of sorts.

    Anyway, I've been using the fgetc and fgets commands to read input from stdin to make things happen, but now I would like to not have to press enter each time I want to do something. I would like to be able to simpley hit a button and have some reaction.

    I'm sure that there is a standard function for this, but I don't know what it is.

    Any suggestions?

    B

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    You can use non-standard <console.h> header file.
    But it is better to use platform specific functions for best performance. Which OS are you using?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    Thanks man,

    I'm working on the OSX command line, so for all intents and purposes BSD.

    B

  4. #4
    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 sure that there is a standard function for this, but I don't know what it is.
    Well there isn't.
    Read the FAQ.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    Ok,

    Read the faq. Always good advice. Looks to me as though what I am really looking for here is the curses.h library.

    My computer has got a curses.h file! I went online and got a little example code. The curses.h library that i've got seems to define all the functions that the example code is looking for, but the linker doesn't seem to be able to find them?????

    What am I doing wrong here?

    B

  6. #6
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    gcc -lncurses

  7. #7
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    -ln curses?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    11
    Rocken!

    Thanks fellas.

    I'm up and running!

    B

  9. #9
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by siavoshkc
    -ln curses?
    Nah, the lib is actually called "ncurses" on most *nix boxes. I believe it stands for "New Curses".

  10. #10
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    So it is -l ncurses, yeah?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  11. #11
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Yup. I have yet to find a system, however, that didn't work with -lncurses.

  12. #12
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869

  13. #13
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    The FAQ talks about getch() in conio.h ... but, again, alas and all that, this is non-standard.

  14. #14
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Quote Originally Posted by twomers
    The FAQ talks about getch() in conio.h ... but, again, alas and all that, this is non-standard.
    Yes, there's no standard way, as Salem already said.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using inline assembly for keyboard input
    By sleventeen in forum C Programming
    Replies: 7
    Last Post: 05-10-2009, 01:31 AM
  2. Keyboard Input
    By CaliJoe in forum C++ Programming
    Replies: 3
    Last Post: 05-08-2009, 09:51 AM
  3. Keyboard input in a Dialog
    By ksarkar in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2005, 05:39 AM
  4. Intercepting keyboard input
    By EvBladeRunnervE in forum Windows Programming
    Replies: 3
    Last Post: 01-08-2004, 09:03 AM
  5. Need help with Console Keyboard Input
    By pawelx2 in forum Game Programming
    Replies: 5
    Last Post: 05-30-2002, 11:03 PM