PDA

View Full Version : ^C and getch() is it possible....



ronin
09-14-2002, 10:17 PM
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




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

Waldo2k2
09-15-2002, 12:17 PM
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.

moi
09-15-2002, 01:28 PM
there are various non-portable library commands dealing with this. what compiler you use?

ronin
09-15-2002, 07:09 PM
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.:)

moi
09-15-2002, 07:45 PM
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 :D

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

ronin
09-15-2002, 07:48 PM
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. ;)

moi
09-24-2002, 05:50 PM
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

ronin
09-26-2002, 08:20 PM
That's moi, but I've "fixed" that little ^C problem. Not a professional approach, but it worked.... I think:p