Keyboard Inputs

This is a discussion on Keyboard Inputs within the C Programming forums, part of the General Programming Boards category; right ive got a problem!would be cool if any1 could help! while(1) { /*get key press*/ gettchar(&ch); switch(ch) { case ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    10

    Keyboard Inputs

    right ive got a problem!would be cool if any1 could help!
    while(1)
    {

    /*get key press*/
    gettchar(&ch);
    switch(ch)

    {
    case '1': /*Start Engine*/
    ready();
    break;
    case '2' : /*test lights*/
    emergency_lights();
    break;

    case'3': /*Exit*/
    exit();
    break;
    }


    } as far as i know this should work so when i press 1,2 or 3 it will jump into certain functions. But it doesnt like gettchar when i compile.above that part of code ive got simple printf's for menu!sorry it must be stupid question but im only begginer.thanx in advance
    Last edited by andreas_himself; 08-15-2008 at 09:11 PM. Reason: not full details

  2. #2
    * noops's Avatar
    Join Date
    Jun 2008
    Posts
    108
    getchar not gettchar

    and i think it is ch = getchar();

  3. #3
    Registered User
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    10
    while(1)
    {
    char ch;
    /*get key press*/
    ch = getchar();
    switch(ch)

    {
    case '1': /*Start Engine*/
    ready();
    break;
    so it should be something like this?

  4. #4
    Registered User Kernel Sanders's Avatar
    Join Date
    Aug 2008
    Posts
    61
    Looks good to me.

    In the future, please put all code between [code] [/code] tags

  5. #5
    Registered User
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    10
    hmm i still get nothing...it compiles but not accessing that while(1)..ive coppied menu from my old project where it works perfectly but not working here.could it be coz of the programme i use?dev c++?

  6. #6
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    it should be case 1: for numbers. No ''

  7. #7
    Registered User
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    10
    thanx guys that helped.one more question?is it possible to make it work automaticly..coz at the moment i use scanf...and if i chose option 1 i have to press ENTER all the time.any ideas about that?

  8. #8
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    No standard function can achieve this I dont think. However there are some in the conio library that can do this I believe.

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    What you are referring to is called unbuffered input. Do a google search for it and you should get some good results.

    As valaris said, there is no standard way to achieve this. The standard io functions typically line buffer console input, which is why you have to hit the ENTER key to signify the end of a line.

  10. #10
    Registered User
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    10
    great stuff guys!it all works now.gonna look up for unbuffred input now.bad thing is that dev c++ doesnt support many libraries maybe anybody knows any other good simply programms to use?

  11. #11
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    Quote Originally Posted by andreas_himself View Post
    dev c++ doesnt support many libraries...
    Dev C++ is an IDE... it has nothing to do with supporting libraries. By default I believe it ships with the MinGW compiler, which you can make work with MANY libraries.

  13. #13
    Registered User
    Join Date
    Aug 2008
    Location
    Bristol
    Posts
    10
    hmm i tried to add
    #include <ncurses.h> and some other,after compiling it said no such a file or directory.
    anyway great help guys

  14. #14
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    Did you download the ncurses library? It doesn't come included with the MinGW compiler...

    If you're on windows I'd suggest getting the pdcurses library, if ncurses is what you're interested in.

  15. #15
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Because I believe it's wcurses on windows.

    ~nm apparently this is an implementation of curses for python.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Keyboard port using other that a keyboard
    By antoinelac in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2008, 02:46 PM
  2. need help for reading two keyboard inputs
    By Diablo02 in forum C# Programming
    Replies: 12
    Last Post: 12-06-2007, 01:21 PM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  4. Child window cant receive keyboard inputs
    By Raison in forum Windows Programming
    Replies: 2
    Last Post: 11-21-2004, 08:46 AM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM

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