Jump to content

Run and console stuff


Recommended Posts

ok,

my problem is that when i run a console application from a GUI application with the flag $STDIN_CHILD (because i need the handle) not only can i not use StdInWrite() but all the data that is supposed to be displayed in the console window is just gone. I need some help on this plz.

Visit my website to see all my finished releases!Releases here:UDFs:GUI ResizingColor List (Web Colors)GUIFade_NearestPower

Link to comment
Share on other sites

ok,

my problem is that when i run a console application from a GUI application with the flag $STDIN_CHILD (because i need the handle) not only can i not use StdInWrite() but all the data that is supposed to be displayed in the console window is just gone. I need some help on this plz.

Can you re-create a small example script?

8)

NEWHeader1.png

Link to comment
Share on other sites

Okay i typed in a hurry so i will kinda elaborate, i have a server app and i need to send messages to it w/o bringing it into focus. This code is in VB 2008 and it is kind of what i want. If this is able to be converted to AU3 i can go from there.

'the subprocedure that actually deals with sending the message to the console window.
    'Using the PostMessage API instead of SendKeys allows us to send characters and keyboard
    'events without needing to bring the target window to the foreground and give it focus.
    Private Sub SendMessageToAscent(ByVal msg As String)
        Dim ascentConsoles As Process() = Process.GetProcessesByName(My.Settings.ascentexe) 'get all running ascent world processes
        For Each console As Process In ascentConsoles   'loop through all running ascent world processes...
            If console.MainWindowTitle.Contains(My.Settings.ascentpath) Then    'and find the one with the window title we need.
                Dim msgToSend As String = msg
                For i As Integer = 0 To msgToSend.Length - 1    'call PostMessage, using the WM_CHAR (0x102) message
                    PostMessage(console.MainWindowHandle, WM_CHAR, Asc(msgToSend(i)), 0)    'and loop through msgToSend, passing each character.
                Next
                PostMessage(console.MainWindowHandle, WM_KEYDOWN, VK_RETURN, 0) 'finally, call PostMessage using WM_KEYDOWN (0x100) with VK_RETURN (Enter).
                Exit For
            End If
        Next
    End Sub

Visit my website to see all my finished releases!Releases here:UDFs:GUI ResizingColor List (Web Colors)GUIFade_NearestPower

Link to comment
Share on other sites

  • Moderators

Okay i typed in a hurry so i will kinda elaborate, i have a server app and i need to send messages to it w/o bringing it into focus. This code is in VB 2008 and it is kind of what i want. If this is able to be converted to AU3 i can go from there.

'the subprocedure that actually deals with sending the message to the console window.
    'Using the PostMessage API instead of SendKeys allows us to send characters and keyboard
    'events without needing to bring the target window to the foreground and give it focus.
    Private Sub SendMessageToAscent(ByVal msg As String)
        Dim ascentConsoles As Process() = Process.GetProcessesByName(My.Settings.ascentexe) 'get all running ascent world processes
        For Each console As Process In ascentConsoles   'loop through all running ascent world processes...
            If console.MainWindowTitle.Contains(My.Settings.ascentpath) Then    'and find the one with the window title we need.
                Dim msgToSend As String = msg
                For i As Integer = 0 To msgToSend.Length - 1    'call PostMessage, using the WM_CHAR (0x102) message
                    PostMessage(console.MainWindowHandle, WM_CHAR, Asc(msgToSend(i)), 0)    'and loop through msgToSend, passing each character.
                Next
                PostMessage(console.MainWindowHandle, WM_KEYDOWN, VK_RETURN, 0) 'finally, call PostMessage using WM_KEYDOWN (0x100) with VK_RETURN (Enter).
                Exit For
            End If
        Next
    End Sub
Here, I'll translate it easy for you:
ControlSend()

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

The way i was attempting to send the messages to the program was using the STDINWrite() Command and starting the server as a child process. As i read the source in VB 2008 from another similar App i found that Subroutine and figures it might work better.

Visit my website to see all my finished releases!Releases here:UDFs:GUI ResizingColor List (Web Colors)GUIFade_NearestPower

Link to comment
Share on other sites

  • Moderators

The way i was attempting to send the messages to the program was using the STDINWrite() Command and starting the server as a child process. As i read the source in VB 2008 from another similar App i found that Subroutine and figures it might work better.

Why did you figure that? Or did you just want someone to translate it so you could see if it would or not?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I was having so much trouble with the STDIN thing and i know this works, but i dislike VB.NET and i didnt know how to translate this into autoit. SO yes i am almost 100% sure it will work, but it is 3:00 AM and, though i found the _WinAPI_PostMessage() function, i am too tired to think straight and translate it right.

Visit my website to see all my finished releases!Releases here:UDFs:GUI ResizingColor List (Web Colors)GUIFade_NearestPower

Link to comment
Share on other sites

  • Moderators

I was having so much trouble with the STDIN thing and i know this works, but i dislike VB.NET and i didnt know how to translate this into autoit. SO yes i am almost 100% sure it will work, but it is 3:00 AM and, though i found the _WinAPI_PostMessage() function, i am too tired to think straight and translate it right.

uh-huh

#include <WinAPI.au3>
Func SendMessageToAscent($s_msg, $s_title = "", $s_exe = "ascent.exe")
    Local $a_ascentConsoles = ProcessList($s_exe)
    Local $a_wlist = WinList(), $a_split = 0
    Local Const $___WM_CHAR = 0x0102
    Local Const $___WM_KEYDOWN = 0x0100
    Local Const $___VK_RETURN = 0x000D
    
    For $i = 1 To $a_ascentConsoles[0][0]
        For $j = 1 To $a_wlist[0][0]
            If WinGetProcess($a_wlist[$j][1]) = $a_ascentConsoles[$i][1] Then
                If $s_title And StringInStr($a_wlist[$j][0], $s_title) = 0 Then ContinueLoop
                $a_split = StringSplit($s_msg, "")
                For $n = 1 To $a_split[0]
                    _WinAPI_PostMessage($a_wlist[$j][1], $___WM_CHAR, Asc($a_split[$n]), 0)
                Next
                _WinAPI_PostMessage($a_wlist[$j][1], $___WM_KEYDOWN, $___VK_RETURN, 0)
            EndIf
        Next
    Next
    Return
EndFunc
Ok, translated... but don't think it works :) Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

@Ron

If $s_title And ....

Did you intend to do that, and in each loop?

8)

Yes, it's only in the 2nd loop if the PID matches the windows process id, so if we're looking for a specific window, and that title doesn't match (actually, if it's not in it, no exact match there confirmed), then it will continue the loop.

The issue the OP is going to have, is this function doesn't attach itself to the thread input. So I doubt seriously this code is going to work. Maybe vb style does it automatically with their postmessage api call, I don't know.

Edit:

AttatchThreadInput() didn't seem to help either.

I'm curious on why ControlSend() won't work, and it's assumed this will?

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...