Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not VB question but a dos question

Status
Not open for further replies.

edderic

Programmer
May 8, 1999
628
is it possible on a batch file to press the CTRL key on the
keyboard ? Eric De Decker
vbg.be@vbgroup.nl

 
I'm not understanding the question. Of course you can PHYSICALLY press the key - so this is obviously not the question. You can (Again &quot;Of Course&quot;) within the batch file obviously program the response to be &quot;as if&quot; the key has been pressed, so this is not the question either. The only other interpertation I see is can you RESPOND to the KeyPress event in the DOS batchfile. Here, I can only refer to 'memory', and it FAILS to respond with a (positive) answer. The only method I recall for communicating with a BATCH file is the PAUSE command coipled with <Ctrl><C>. This allows a batch file to &quot;prompt&quot; the user for SOME action. If the 'Action&quot; is <Ctrl><C>, the operation aborts, otherwise it continues with the next line. A more flexible set of logic paths is generally implemented with the errorlevel function.

I know that PcMag (now ZdNet) did some really weird and wild &quot;Batch Programming&quot; in the days of yore. I do not know if they retain the archives of the things they generated, but I do recall being AMAZED that you COULD do some of the operations they implemented - and even MORE aMaZeD that anyone would contort themselves to dO It.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Of course, the obvious question that is being asked, but that has somehow been missed in the above analysis, is whether it is possible to mimic actually pressing the CTRL key. Unfortunately I've been drinking beer in somewhat excessive quantities, so I'm in no position to answer the question properly...
 
Eric,
You can't directly mimic pressing the KEY from VB, but there is no reason why you could not write a small C++ (16 bit, not 32 bit . . . assuming that this is for a TRUE DOS machine)application (EXE or COM model) that you caould call from your BAT file and that application would do it for you.




strongm,
Pass me one of those beers! ;-) - Jeff Marler B-)
 
i am a VB programmer and not C++ (to do it on VB its a lot of files(dll's) for a simple press the CTRL key)

So i thinc this to do with a batch file... Eric De Decker
vbg.be@vbgroup.nl

 
Hello again,

Try this out:

37. A pause which requires Ctrl+Break instead of any key.
After Ctrl+Break, there is the usual choice to continue or abort.
COMMAND nul /CECHO ;|CHOICE /C; /N

They are trapping for a Ctrl + Break character here and this could give you a leg up on how to trap for it in other cases.
 
I am still confused about whether you want to detect a CTRL keypress or set the shift-flag for the CTRL key. Reading the keypress in a batch file is relatively simple. MS-DOS doesn't provide a method (internal or external) to read the key-state... but you could call a little program from the batch file designed to monitor the shift-states until a certain condition is met.

This was written in Quick Basic. It simply loops until a CTRL key is pressed.[tt]

DEFINT A-Z
TYPE RegTypeX
AX AS INTEGER
bX AS INTEGER
CX AS INTEGER
dX AS INTEGER
bp AS INTEGER
Si AS INTEGER
di AS INTEGER
FLAGS AS INTEGER
Ds AS INTEGER
ES AS INTEGER
END TYPE
DIM inregs AS RegTypeX, OutRegs AS RegTypeX
inregs.AX = &H1200
DO
CALL INTERRUPTX(&H16, inregs, OutRegs)
IF (OutRegs.AX AND 2 ^ 2) THEN
PRINT &quot;CTRL key pressed&quot;
SYSTEM
END IF
LOOP
[/tt]
There is an obvious problem using this approach under Windows: the keyboard state monitored in the batch file is meaningless in any other thread.

You might be able to set the shift state of the CTRL key by creating an OS hook with Interrupt 15h, function 4Fh but you will have the same problem. The results will only apply to the current copy of the command interpreter.

Can you get or set the the CTRL key in a batch file? Yes. Will that ability provide a useful tool? I doubt it.

VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top