Sign in to follow this  
Followers 0
LiLShinta

Send Key To Process

6 posts in this topic

ahmm.. what if i want to get the list of process working on my my and then when It found the process, it will send keys on it.

or maybe how to get the window handle of that process to Send Keys on it... please help.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm having a hard time understanding the first question of yours, but for the last part, you could use something like this:

Edit: Fixed a small error in my code(whops):

#include <WinAPI.au3>

Run("notepad.exe")
ProcessWait("notepad.exe")

Dim $aNotepad = _ProcessGetWinEx("notepad.exe") ; For example to find notepad's window from it's process

ControlSend($aNotepad[1], "", "", "123abc - ControlSend{enter}") ; One way, only works on some windows(note: controlID "can" be set to "")

WinActivate($aNotepad[1])
Send("123abc - normal Send") ; Another way, if you have nothing against activating the window first.

Func _ProcessGetWinEx($ivPid, $svClass = "")
   
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
   
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
   
    For $i = 1 To $avwArray[0][0]
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or _WinAPI_GetClassName($avwArray[$i][1]) = $svClass Then
                $avRet[0] += 1
                ReDim $avRet[$avRet[0]+1]
                $avRet[$avRet[0]] = $avwArray[$i][1]
            EndIf
        EndIf
    Next
   
    Return $avRet
   
EndFunc
Edited by FreeFry

Share this post


Link to post
Share on other sites

what if the window is at state of @SW_HIDE? will the control send still works? thanks for the code...

Share this post


Link to post
Share on other sites

Sorry, I noticed I made an error in the first code I posted(I forgot that my _ProcessGetWinEx function returns an array of windows(if the process should happen to own more windows than one)).

I fixed that code, and I'm not sure ControlSend works for hidden windows, but the normal Send does, if you give focus to the window first.

Example:

#include <WinAPI.au3>

Run("notepad.exe", "", @SW_HIDE)
ProcessWait("notepad.exe")

Dim $aNotepad = _ProcessGetWinEx("notepad.exe") ; For example to find notepad's window from it's process
ControlSend($aNotepad[1], "", "", "123abc - ControlSend{enter}") ; This does not work
WinActivate($aNotepad[1])
Send("123abc - normal Send") ; This does work though
WinSetState($aNotepad[1], "", @SW_SHOW)

Func _ProcessGetWinEx($ivPid, $svClass = "")
   
    $ivPid = ProcessExists($ivPid)
    If Not $ivPid Then Return(SetError(1, 0, 0))
   
    Local $avwArray = WinList()
    Local $avRet[1] = [0]
   
    For $i = 1 To $avwArray[0][0]
        If WinGetProcess($avwArray[$i][1]) = $ivPid Then
            If $svClass = "" Or _WinAPI_GetClassName($avwArray[$i][1]) = $svClass Then
                $avRet[0] += 1
                ReDim $avRet[$avRet[0]+1]
                $avRet[$avRet[0]] = $avwArray[$i][1]
            EndIf
        EndIf
    Next
   
    Return $avRet
   
EndFunc

Share this post


Link to post
Share on other sites

how will my code goes that be if I would like to send in a hidden window.. ahmm.. or on trhe window using gdi32.dll?? are you aware of it??please teach me..

Share this post


Link to post
Share on other sites

Look at my previous example, it uses normal send, and it works on the hidden notepad window.

Share this post


Link to post
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
Sign in to follow this  
Followers 0