Thread: cntrl getch

  1. #1
    Unregistered
    Guest

    Question cntrl getch

    In many programs to do commands you hit cntrl-a or somthing to save in consle mod how do you do this i have no clue at all im thinking its done with getch() some how but im not sure

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    Control-keypress "commands" are a way of sending a signal to a running process. A signal is a type of inter-process comunication that alerts the program to an exceptional condition and tells it to do something (usually quit now, save and quit, or set some flag). I'm not sure how to handle signals in DOS, but if you query a decent search engine for trapping signals in dos or the like, you should be able to find something.

    starX
    www.axisoftime.com
    ---------------
    starX
    www.axisoftime.com

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    2

    Lightbulb Re

    Yes it can be done with getch().
    Getch() return's you ASCII value of character, if you press normal key. When you press smthinng like Ctrl+A firstly getch() returns zero. So you must call getch() once more to get special scancode number. If you want to handle keys like ctrl+a or cursor keys this code tels you what scancode appropiate to your ctrl+smthing:

    #include <conio.h>
    #include <stdio.h>
    main()
    {
    char c;
    printf("Press something!\n");
    if((c=getch())==0)
    {
    c=getch(); //getch() must be call onesmore to
    //get scancode
    printf("You press smthing special\n);
    printf("Scancode:%d",c);
    }
    else
    {
    printf("You press normal key\n");
    printf("ASCII value:%d",c);
    }
    return(0);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Pls repair my basketball program
    By death_messiah12 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2006, 05:15 AM
  3. Pause a C program without getch()
    By swgh in forum C Programming
    Replies: 4
    Last Post: 02-20-2006, 11:24 AM
  4. Clearing input buffer after using getch()
    By milkydoo in forum C++ Programming
    Replies: 3
    Last Post: 07-21-2003, 11:04 PM
  5. Using getch()
    By pr0ficient in forum Linux Programming
    Replies: 2
    Last Post: 07-26-2002, 05:59 AM