Thread: ^C and getch() is it possible....

  1. #1
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350

    ^C and getch() is it possible....

    Hey guys; once again I could use some help. Is it possible to trap ^C so it doesn't exit to dos when using getch() to read input? I've used

    Code:
    unsigned keyRead;
    
    keyRead = getch();
    
    if(iscntrl(keyRead))
        printf("control key 0x%x\n", keyRead);
    This seems to trap all cntrl keys except for ^C which, when pressed, immediately exits to dos. I'd like to do it without using dos vector or bioskeybrd type of calls. Does anyone have any ideas?

    TIA
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  2. #2
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    Well, the program is running in a dos box, which conforms to most dos features (obviously including the ctrl+c command). Since it's a command for DOS itself, not your program, i don't think you can use getch to control it's use. See getch is running at the program level, the ctrl+c command is running at the OS level (DOS). Therefore, you must manipulate the DOS environmental variables to override the command temporarily. I'm not familiar with all the variables so you'll have to look into it, but i'm almost positive it can't be done with the functions included in C/C++. You'll have to do some system calls to dos from your program to manipulate the variables, that's about all i can give you. good luck.

  3. #3
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    there are various non-portable library commands dealing with this. what compiler you use?
    hello, internet!

  4. #4
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    I figured as much... I guess I'll have to turn to inline asm to manipulate the keyboard.

    The compiler is MSVC 1, but I'm working with a pure 16 bit dos app.

    Thanks for the feedback.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  5. #5
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by ronin
    I figured as much... I guess I'll have to turn to inline asm to manipulate the keyboard.

    The compiler is MSVC 1, but I'm working with a pure 16 bit dos app.

    Thanks for the feedback.
    msvc 1? *winces* good luck

    djgpp is a well-documented easy to use very powerful 32-bit dos compiler, if your interested
    hello, internet!

  6. #6
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Heh, I'm working with dos apps for it's ease, but I also have codewarrior pro 5 and visual studio 6 for when I decide to move to 32 bit win apps.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  7. #7
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by ronin
    Heh, I'm working with dos apps for it's ease, but I also have codewarrior pro 5 and visual studio 6 for when I decide to move to 32 bit win apps.
    like i said, if you want to stick with dos, djgpp is there
    hello, internet!

  8. #8
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    That's moi, but I've "fixed" that little ^C problem. Not a professional approach, but it worked.... I think
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

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. Clearing input buffer after using getch()
    By milkydoo in forum C++ Programming
    Replies: 3
    Last Post: 07-21-2003, 11:04 PM
  4. Problems with getch()
    By GrNxxDaY in forum C++ Programming
    Replies: 14
    Last Post: 08-12-2002, 02:11 AM
  5. Using getch()
    By pr0ficient in forum Linux Programming
    Replies: 2
    Last Post: 07-26-2002, 05:59 AM