Judgey
August 7th, 2001, 05:47 AM
Hello Guru's
Can Any of you help mw with ths one, I would like to sendkeys to a DOS App opened as a window in Win98 using a standard .pif file. I can activate and open it but sendkeys are ignored. Can somebody tell me how to go about it ?
Many thanks in anticiaption . .
Work is necessary for man. Man invented the alarm clock.
coolbiz
August 7th, 2001, 06:38 AM
Maybe you can post your code too so that we can take a look at it. There have been a lot of discussion on doing so in this forum which basically making that DOS box as the active window and using SENDKEYS to send the keyboard input.
The simplest way is such:
private Sub Command1_Click()
Shell MyDosApp.Exe, vbNormalFocus
SendKeys "My_Dos_Command{ENTER}", false ' returns right after key is sent
SendKeys "My_Dos_Wait_Command{ENTER}", true ' does not return until the command is processed by
' MyDosApp.exe
End Sub
-Cool Bizs
Iouri
August 7th, 2001, 07:04 AM
I don't like send keys in general. here the program how to create a console and read and write to it
'that is bus module (no forms), project starts in sub main
Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function FreeConsole Lib "kernel32" () As Long
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, _
ByVal lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, _
lpReserved As Any) As Long
Private Declare Function SetConsoleMode Lib "kernel32" (ByVal hConsoleOutput As Long, _
dwMode As Long) As Long
Private Declare Function ReadConsole Lib "kernel32" Alias _
"ReadConsoleA" (ByVal hConsoleInput As Long, ByVal lpBuffer As String, ByVal _
nNumberOfCharsToRead As Long, lpNumberOfCharsRead As Long, lpReserved As Any) As Long
Private Const STD_INPUT_HANDLE = -10&
Private Const STD_OUTPUT_HANDLE = -11&
Private Const STD_ERROR_HANDLE = -12&
Private Const ENABLE_LINE_INPUT = &H2
Private Const ENABLE_ECHO_INPUT = &H4
Private Const ENABLE_MOUSE_INPUT = &H10
Private Const ENABLE_PROCESSED_INPUT = &H1
Private Const ENABLE_WINDOW_INPUT = &H8
Private Const ENABLE_PROCESSED_OUTPUT = &H1
Private Const ENABLE_WRAP_AT_EOL_OUTPUT = &H2
Private Sub Main()
Dim sOutPut As String
Dim lHInput As Long, lHOutPut As Long, lHErr As Long
Dim sInput As String * 255
'Create an instance of the console
AllocConsole
'Get handle to STD_INPUT, STD_OUTPUT, STD_ERROR
lHInput = GetStdHandle(STD_INPUT_HANDLE)
lHOutPut = GetStdHandle(STD_OUTPUT_HANDLE)
lHErr = GetStdHandle(STD_ERROR_HANDLE)
'Allow Input
SetConsoleMode lHInput, ENABLE_ECHO_INPUT
'Write output
sOutPut = "Enter a number between 1 and 10." & vbCrLf
WriteConsole lHOutPut, sOutPut, Len(sOutPut), vbNull, vbNull
'Read Input
ReadConsole lHInput, sInput, Len(sInput), vbNull, vbNull
sInput = TrimWithoutPrejudice(sInput)
If IsNumeric(sInput) Then
If CLng(sInput) < 1 Or CLng(sInput) > 10 Then
sOutPut = "You did not follow the instructions"
Else
sOutPut = "You entered " & sInput
End If
Else
sOutPut = "You did not follow the instructions"
End If
sOutPut = sOutPut & vbCrLf
WriteConsole lHOutPut, sOutPut, Len(sOutPut), vbNull, vbNull
sOutPut = "Press Enter to exit" & vbCrLf
WriteConsole lHOutPut, sOutPut, Len(sOutPut), vbNull, vbNull
ReadConsole lHInput, sInput, Len(sInput), vbNull, vbNull
sInput = TrimWithoutPrejudice(sInput)
'Finished
FreeConsole
End Sub
Public Function TrimWithoutPrejudice(ByVal InputString As String) As String
'http://www.freevbcode.com/ShowCode.ASP?ID=104
Dim sAns As String
Dim sWkg As String
Dim sChar As String
Dim lLen As Long
Dim lCtr As Long
sAns = InputString
lLen = Len(InputString)
If lLen > 0 Then
'Ltrim
For lCtr = 1 To lLen
sChar = Mid(sAns, lCtr, 1)
If Asc(sChar) > 32 Then Exit For
Next
sAns = Mid(sAns, lCtr)
lLen = Len(sAns)
'Rtrim
If lLen > 0 Then
For lCtr = lLen To 1 Step -1
sChar = Mid(sAns, lCtr, 1)
If Asc(sChar) > 32 Then Exit For
Next
End If
sAns = Left$(sAns, lCtr)
End If
TrimWithoutPrejudice = sAns
End Function
Iouri Boutchkine
iouri@hotsheet.com
Judgey
August 7th, 2001, 08:30 AM
Hi Louri,
Thanks for your code, I think its a bit advanced for me though, I can't quite fatham out how I incorporate the companies Dos EXE file, It is basically a login Name and Password, then a series of Menus which can be activated by a Letter or arrow keys. It is a true DOS App not the DOS environment, can the writeconsole be used to send strings to the DOS Application ?
Work is necessary for man. Man invented the alarm clock.
Judgey
August 7th, 2001, 08:31 AM
Cheers Coolbiz,
This is the Code I already have and nothing seems to happen ?, anyother Ideas ?
Work is necessary for man. Man invented the alarm clock.
coolbiz
August 7th, 2001, 01:39 PM
Post the code that you currently have or email it to me. I'll take a look at it.
-Cool Bizs