jonnyg@umd5.umd.edu (Jon Greenblatt) (03/29/88)
I need a description of how a TSR such as a dos editor can detect if dos is in the command prompt state. I want to write a program that checks to see if the PC has been idle at the command prompt for more than five minutes then stuff the keyboard buffer with the keys needed to execute an idle program. This may seem like an awkward way of doing things but I have very good reasons for doing this. I just need a description of how to detect if the command prompt is active when writing a TSR for int XX (XX = 16h, 21h). Thanks very much, Jon Greenblatt
madd@bu-cs.BU.EDU (Jim Frost) (03/31/88)
In article <2513@umd5.umd.edu> jonnyg@umd5 (Jon Greenblatt) writes: > I need a description of how a TSR such as a dos editor can detect >if dos is in the command prompt state. I want to write a program that >checks to see if the PC has been idle at the command prompt for more than >five minutes then stuff the keyboard buffer with the keys needed to execute >an idle program. [...] I just need a description of how to >detect if the command prompt is active when writing a TSR for >int XX (XX = 16h, 21h). Thanks very much, If you're using MS-DOS 3.0 or greater, it's not that difficult. I'd try something along the following lines. Chain your TSR to int 16h so you'll know when you're being asked for keyboard input. Whenever you're called, poll to see if there are keys in the keyboard buffer. If there are, call the old routine to return them. If there are not, keep checking to see if you're time has expired. If your time expires, call int 21h function 62h (get current program's PSP) and compare the environment variable COMSPEC to the curren't program's name (pointers to the environment and the program's name are stored in the PSP, see your DOS tech manual). If they don't match, call the old int 16h to wait on a character, since you know that the program isn't going to change until after at least one character. If you do match COMSPEC and the program name, their shell is running. You don't need to stuff the keyboard buffer with anything because your program can effectively be the keyboard buffer. Set something that lets you know you're dumping characters, then dump one at a time until your string is exhausted. Then go back into the normal wait-mode to see if it'll idle out again. You might want to check for reentrancy problems with MS-DOS function 62h, but I don't expect you'll have to worry about them. That function is probably very simple (just check a table entry). Hope this helps, jim frost madd@bu-it.bu.edu [Note: followup-to: should contain the name of a newsgroup, not a person]