Sending Keystrokes, DOS Applications
and Blanked Screen
Keywords: sendkey keystroke key send dos file function call flashes black
Here are a few things to keep in mind when sending keystrokes to DOS apps:
- To send keystrokes to DOS sessions, make sure the DOS window is in windowed mode, rather than in full screen mode. If you do not use Windowed mode, when you run your DOS app or DOS BAT from WinBatch, the screen will flash black when the app launches.
- We recommend using windowed DOS mode at all times, since some keystrokes cannot be sent to full DOS window. For example, the ENTER *must* be sent when in Windowed mode, otherwise it won't work (due to some unfathomable Windows quirk).
- To set your DOS program to windowed mode, set up a DOS PIF file (_Default.pif) file to run in a windowed state, and make sure the Close Window on Exit option is checked.
- If the program has its own .pif file, make the changes in that .pif. The PIF file needs to be in the same directory as the BAT file, or in the C:\WINDOWS directory. To set up one master PIF file with the appropriate settings, so that all your DOS apps can use one BAT and one PIF file, see the file "The Mother of All PIF Files" elsewhere on this website.
- In order to send the UP/DOWN arrows to a DOS app, the NumLock key must be off. You can use KeyToggleSet to turn the NumLock to off.
- Use the "Run" function, rather than the "RunWait" function, to launch your DOS app, if you're going to send keystrokes to it, i.e.:
run("MYDOS.BAT", "")The SendKeysTo function makes sure the window you want is on top (activated) first. The SendKey function sends blindly to whatever window is on top.
- You should use lower-case letters to represent Alt-key combinations and other menu shortcut keys, e.g.
Sendkeysto("Microsoft Word", "!fo") ; send File Open keystrokes
- To enter Ctrl-Shift-F7:
SendKeysto("Microsoft Word", "^+{F7}")- You may also repeat a key by enclosing it in braces, followed by a space and the total number of repetitions desired.
- To type 20 asterisks:
SendKeysto("Microsoft Word","{* 20}")
- To move the cursor down 8 lines:
SendKeysto("Microsoft Word","{DOWN 8}")It is possible to use SendKey to send keystrokes to a DOS application, but only if you are running Windows in 386 Enhanced mode. You would then transfer the keystrokes to the DOS application via the Clipboard. It is only possible to send standard ASCII characters to DOS applications; you cannot send function key or Alt-key combinations.Example:
; start Notepad, and use *.* for filenames Run("notepad.exe", "") SendKey("!fo*.*~") ; run DOS batch file which starts our editor Run("edit.bat", "") ; wait 15 seconds for editor to load Timedelay(15) ; send string (with carriage return) to the clipboard ClipPut("Hello%@crlf%") ; paste contents of clipboard to DOS window SendKey("!{SP}ep")In those cases where you have an application which can accept text pasted in from the clipboard, it will often be more efficient to use the ClipGet function:
Run("notepad.exe", "") ; copy some text to the clipboard ClipPut("Dear Sirs:%@crlf%%@crlf%") ; paste the text into Notepad (using Shift-Ins) SendKey("+{INSERT}")A WIL program cannot send keystrokes to its own WIL Interpreter window.Note: If your SendKey statement doesn't seem to be working (eg., all you get are beeping noises), you may need to place a WinActivate statement before the SendKey statement to insure that you are sending the keystrokes to the correct window.
See Also:
ClipGet, SnapShot, WinActivatePulling up the DOS Window Menu
Question:
In the following code:SendKey("!(SP)EP")everything works perfectly except no sendkey!Answer:
The stuff around the SP must be the special curly braces rather than the normal parenthesis. Everything you mentioned sounds reasonable, but I failed to detect the required CURLY BRACES around the SP.More info..............
SendKey("!{SP}EP")Actually the following will also work:SendKey("! EP") ;<<<- when you just type a space for a spaceAlso as a point of nitpicking:SendKey("! EP")is the same as:
ALT SPACE SHIFTDOWN e p SHIFTUP.However, I don't really think you're supposed to do it that way. So instead use the lower case example:
SendKey("! ep")How to Send a Backslash to a DOS Window
Question:
On my pc i have windows98 german version. I´m not capable to enter a backslash in a windowed dos box. The backslash is ignored in the SendKey command. The key combination to enter a "\" is "ALT-GR \". How can i enter a backslash in a windowed dos box?Answer:
Clipput("c:\temp\xyz.txt") SendKey("! ep") ; Alt space E P
Article ID: W12902Filename: Sending Keystrokes to DOS Apps and Blanked Screen.txt