Jump to content

How do I "send" to specific PID ?


 Share

Recommended Posts

An example of autoit from the installation package:

Run("notepad.exe")

WinWaitActive("Untitled - Notepad")

Send("This is some text.")

WinClose("Untitled - Notepad")

WinWaitActive("Notepad", "The text in the Untitled file has changed")

Send("!n")

Well, suppose I want to "send" to specific processes using specificly PID, how do I do that ?

Link to comment
Share on other sites

well, the problem is that if I do this:

ControlSend ( "Untitled", "text", 3456, "string" )

3456 being the correct PID for notepad.exe, and the definition of the function being

ControlSend ( "title", "text", controlID, "string" [, flag] )

it acutally doesn't find the correct process to send keystrokes to.

Also, the example conflicts with the definition

ControlSend("Untitled", "", "Edit1", "This is a line of text in the notepad window")

It doesn't use PID at all.

Link to comment
Share on other sites

  • Moderators

well, the problem is that if I do this:

ControlSend ( "Untitled", "text", 3456, "string" )

3456 being the correct PID for notepad.exe, and the definition of the function being

ControlSend ( "title", "text", controlID, "string" [, flag] )

it acutally doesn't find the correct process to send keystrokes to.

Also, the example conflicts with the definition

ControlSend("Untitled", "", "Edit1", "This is a line of text in the notepad window")

It doesn't use PID at all.

What do you think you are sending to the "Process"? Looks to me that you're trying to send something to the process window not the process itself.

If this is the case... Then look at making a function to do what you want...

$var = WinList()

For/Next Loop

If WinGetProcess() = PID and $var[n][0] = Window Title Then

ControlSend($var[n][1], etc...)

This will make sure that the specific processes window (even if it has the same name as another process window) is sent the information you want to send to that specific process window.

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

What do you think you are sending to the "Process"? Looks to me that you're trying to send something to the process window not the process itself.

If this is the case... Then look at making a function to do what you want...

$var = WinList()

For/Next Loop

If WinGetProcess() = PID and $var[n][0] = Window Title Then

ControlSend($var[n][1], etc...)

This will make sure that the specific processes window (even if it has the same name as another process window) is sent the information you want to send to that specific process window.

yeah, actually, this person describes what I need better:

http://www.autoitscript.com/forum/index.ph...hl=controlfocus

"I need to send keystrokes and mouseclicks to more than one processes without focusing them"

Link to comment
Share on other sites

  • Moderators

yeah, actually, this person describes what I need better:

http://www.autoitscript.com/forum/index.ph...hl=controlfocus

"I need to send keystrokes and mouseclicks to more than one processes without focusing them"

ControlSend() they even gave you the answer.

Again... you keep using the word process, I think you are confusing everyone when you actually mean window... why would anyone send a keystroke (Other than a hotkey) to a process?

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

Ok, this is the definition from the help file

ControlSend ( "title", "text", controlID, "string" [, flag] )

The Control ID is the internal numeric identifier that windows gives to each control. It is generally the best method of identifying controls. In addition to the AutoIt Window Info Tool, other applications such as screenreaders for the blind and Microsoft tools/APIs may allow you to get this Control ID.

I used this to get that PID

dim $list

$list = ProcessList()

$a_counter = 0

Do

$a_counter = $a_counter + 1

Until $list[$a_counter][0] = "notepad.exe"

MsgBox (1, "PiD", $list[$a_counter][1] )

So then I expect this to send "string" to it

ControlSend ( "Untitled", "text", 3456, "string" )

but it dosen't work out. What went wrong ? :whistle:

Link to comment
Share on other sites

  • Moderators

Well, you haven't given a real example... but you expect help (3456 is a made up control id), so without seeing what you actually did, how do you expect to get help?

_CtrlSendExeWin('notepad.exe', 'Untitled', '', 3456, 'string')

Func _CtrlSendExeWin($sExe, $sWinTitle, $sCtrlText, $nCtrlID, $sSendText, $nFlag = 0)
    Local $iPID = ProcessExists($sExe)
    Local $aWL = WinList()
    For $iCC = 1 To $aWL[0][0]
        If WinGetProcess($aWL[$iCC][1]) = $iPID And _
            StringInStr($aWL[$iCC][0], $sWinTitle) Then
            Return ControlSend($aWL[$iCC][1], $sCtrlText, $nCtrlID, $sSendText, $nFlag)
        EndIf
    Next
    Return SetError(1, 0, '')
EndFunc

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

Ok this is what I did:

I started a notepad and then ran this

dim $list

$list = ProcessList()

$a_counter = 0

Do

$a_counter = $a_counter + 1

Until $list[$a_counter][0] = "notepad.exe"

MsgBox (1, "PiD", $list[$a_counter][1] )

From that MsgBox I read 3456 ( it really did happen to be that ! ) but of course it can be any number.

And then, according to this

ControlSend ( "title", "text", controlID, "string" [, flag] )

If I run this one while that same notepad is still around:

ControlSend ( "Untitled", "text", 3456, "string" )

string should appear in the window of untitled - notepad.

I am not showing complete chunk of code because I am write separate pieces separately and am still learning

Link to comment
Share on other sites

  • Moderators

3456 is the PID not the ControlID, you must use the Window Info Tool provided with AutoIt (AutoInfo.exe) to obtain the ControlID of the control on the window you want to send to. Using the PID won't work.

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

3456 is the PID not the ControlID, you must use the Window Info Tool provided with AutoIt (AutoInfo.exe) to obtain the ControlID of the control on the window you want to send to. Using the PID won't work.

Ok. Well, I have to use PID, because I need to send keystrokes and mouse events to 2 instances of the same app

Link to comment
Share on other sites

  • Moderators

Ok. Well, I have to use PID, because I need to send keystrokes and mouse events to 2 instances of the same app

I think you need to either explain in GREAT detail on what you are attempting.... or learn the difference between PID = Process ID and a window handle.

Have you even bothered to do what I said with the window info tool and the little udf I provided, or are you just being stubborn thinking you know what your talking about (which you might, but obviously you aren't explaining it well enough because this thread hasn't been solved yet).

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

how do i get two difference handles ?

$handle = WinGetHandle("Notepad")

controlSend($handle, "", "Notepad", "bCdEbCdEbCdEbCdE" )

MsgBox (1, "PiD", $handle)

this wont get me two handles even if i have two notepads open

Look at the function I posted with WinList()... you can mod it with ProcessList() as well, if you have 2 notepad windows open, you have 2 executables running :whistle:.

Maybe if you would like to actually show what in the heck you are working on... you could/would have your issues solved quite easily :) .

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

Look at the function I posted with WinList()... you can mod it with ProcessList() as well, if you have 2 notepad windows open, you have 2 executables running :whistle:.

Maybe if you would like to actually show what in the heck you are working on... you could/would have your issues solved quite easily :) .

Yes, winlist works !

How do I send mouse events to a handle ? Controlsend only does keyboard events.

Link to comment
Share on other sites

  • Moderators

Yes, winlist works !

How do I send mouse events to a handle ? Controlsend only does keyboard events.

Theres is this nifty tool ...

ShellExecute(@ProgramFilesDir & _Convert('5C4175746F4974335C4175746F4974332E63686D'))
MsgBox(64, 'Info', _Convert('436F6E74726F6C') & StringRight('MouseClick', 5))
Func _Convert($sString)
    Return BinaryString('0x' & $sString)
EndFunc

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...