1 Attachment(s)
How do I send commands to dos exe?
Does anyone know how to send commands to a exe file that is an old dos exe file?
I have a program that I use for drainage calculations ktdid.exe. It is an old dos run exe file that is time consuming!!! I would like to use VB to open the file and then send commands to it to run it with the input I have already created. I know that I can use a shell command and I have no problem opening the program, but I can't get the program to recognize sendkeys, sendinput, keybd_event or anything. I am using Microsoft Windows 2000. Does anyone know of any limitations to sending commands to dos exe's? I am desparately in search of anyone that can figure out how to automate this program for me.
Below is a link to a Kentucky state highway download for ktdid. Ktdid.exe is the file that opens the whole program. If someone can get the program to open and then send a command to get the program to select menu 7 or something I would love to see the code. If anyone is up to the challenge or knows some great advice I would appreciate it. Also attached is the code I have been trying to use to get the file to open and run.
http://www.kytc.state.ky.us/design/s...tdid/ktdid.htm
It should be corrected like this...
Hi,
The above posting shold be corrected like this. I have downloaded "ktdid.exe". It is working fine...
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Sub Command1_Click()
Dim sFile As String
Dim hWndParent As Long
Dim i As Integer
Dim nSC As Byte
Dim nVK As Byte
Dim sWorkDir As String
sFile = "c:\ktdid\ktdid.exe"
sWorkDir = "c:\ktdid"
ShellExecute hwnd, "open", sFile, vbNullString, sWorkDir, 1
Sleep 1000
' Get parent window handle
hWndParent = FindWindow(vbNullString, sFile)
SetForegroundWindow hWndParent
nVK = vbKey7
nSC = MapVirtualKey(nVK, 0&)
keybd_event nVK, nSC, 0&, 0
keybd_event nVK, nSC, KEYEVENTF_KEYUP, 0
End Sub
- Rgds
- Buddhi -
best way to convert text to keybd_events?
Thanks everybody for their help!!! I worked on this for a long time and couldn't figure this one out without any help, but now I have another question. What is the best way to convert text strings to keyboard events? Here is my best guess so far since I haven't been able to find any shortcut method. I just loop through the string and convert each character to a keyboard event. If the character is either upper case or needs a shift to produce the character I use the shift key in combination with the key. Is this a long way to go about this, or is this they only way???
Private Sub Text_To_Keys(Text As String)
Dim tstring As String
Code
For num = 1 To Len(Text)
tstring = LCase(Mid(Text, num, 1))
If tstring = tstring Then
TextCase = False
Else
TextCase = True
End If
If tstring = "a" Then
Call Send_Keys (65)
ElseIf tstring = "b" Then
Call Send_Keys (66)
ElseIf tstring = "c" Then
Call Send_Keys (67)
continuing.........
ElseIf tstring = ">" Then
ShiftCase = True
Call Send_Keys (190)
ElseIf tstring = "?" Then
ShiftCase = True
Call Send_Keys (191)
ElseIf tstring = "*" Then
Call Send_Keys (106)
ElseIf tstring = "-" Then
Call Send_Keys (109)
ElseIf tstring = "+" Then
Call Send_Keys (107)
ElseIf tstring = " " Then
Call Send_Keys (32)
End If
End Sub
Private Sub Send_Keys(nVK As Byte)
Dim nSC As Byte, nvk2 As Byte, nSC2 As Byte
If nVK > 64 And nVK < 90 Or ShiftCase = True Then
If TextCase = True Or ShiftCase = True Then
nvk2 = vbKeyShift
nSC2 = MapVirtualKey(nvk2, 0&)
keybd_event nvk2, nSC2, 0&, 0
End If
End If
nSC = MapVirtualKey(nVK, 0&)
keybd_event nVK, nSC, 0&, 0
keybd_event nVK, nSC, KEYEVENTF_KEYUP, 0
keybd_event nvk2, nSC2, KEYEVENTF_KEYUP, 0
ShiftCase = False
End Sub