Jump to content

Handles for Send?


Recommended Posts

Hello everyone, i'm trying to find a way to use the sort of 'Send' command to send something directly into a given window. I'm using the code beneath to get the HWND handle of the searched screens. This piece of code will be waiting for 2 similar screens to save their handles, so i can use those handles later on to send keys directly into one of the windows. Using window titles just wont do much good..

Now here is the part where i am stuck. It sounds silly, but i aint got the slightest clue how to get keys into the windows. I can do this using ControlSend like on the example of notepad, only i dont know how to be able to use my received handles in that case. Any help would be appreciated. Thank you very much.

; Only start parsing all the screens when the handles arent occupied yet.
    If $handleMaster = -1 OR $handleSlave = -1 Then
        
        ; Get a list of all the current windows.
        $windowList = WinList()

        ; Parse trough all the finds in the array.
        For $i = 1 to $windowList[0][0]
            
            ; Only check on windows that actually have a title.
            If $windowList[$i][0] <> "" AND BitAnd( WinGetState($windowList[$i][1]), 2 ) Then
                
                ; If this one is a searched screen, save the handle properly.
                If $windowList[$i][0] = $windowSearch AND $windowList[$i][1] <> $handleMaster AND $windowList[$i][1] <> $handleSlave Then
                
                    If $handleMaster = -1 Then
                        $handleMaster = $windowList[$i][1]
                        MsgBox( 0, $windowList[$i][0], "Master handle '" & $windowList[$i][1] & "'" )
                    Else
                        $handleSlave = $windowList[$i][1]
                        MsgBox( 0, $windowList[$i][0], "Slave handle '" & $windowList[$i][1] & "'" )
                    EndIf
                
                EndIf

            EndIf
        
        Next
    
    EndIf
Link to comment
Share on other sites

Sure would be nice to have a WinSend function similar to ControlSend so you can send a key sequence or mouse clicks to a window that does not have focus.

Wonder if you can use ControlSend with the window handle as the controlID? Somthing like this:

ControlSend($hwnd, $hwnd, "{ENTER}")

I can't test this at the moment. Maybe you could try it and give some info on what happened?

This introduction to journalhooks could give some clues. Especially if we do a search for WH_JOURNALPLAYBACK after reading it.

Link to comment
Share on other sites

Something such as that sadly didnt work. It does work with ControlSend to a specific window title, but when there are 2 duplicate titels that method just wont work. I really didnt play on hooking anything with C really, and its not supposed to. There should be some way..

Link to comment
Share on other sites

A idea, rename one of the windows.. Or rename 'EXAMPLE Title 1', 'EXAMPLE Title 2'

Example title, being what ever program you want to send to.

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Link to comment
Share on other sites

Something such as that sadly didnt work. It does work with ControlSend to a specific window title, but when there are 2 duplicate titels that method just wont work. I really didnt play on hooking anything with C really, and its not supposed to. There should be some way..

Did you try using the window handle as the window id to, and not the title?

As I read the help file for WinList you get the handle automatically. The handle is, as you know, unique to windows. SO it is a better id than the window title. I'm still sorry I can't do any testing as I don't have a windows OS available.

Link to comment
Share on other sites

Maybe I misunderstood something, but, you said you could get ControlSend to work if you used the Window Title, correct? Well, did you know that in ControlSend (or any of the window functions for that matter) "title" is interchangable with a window handle?

ie:

ControlSend("Untitled", "", "Edit1", "Text")

Is equivalent to:

$handle = WinGetHandle("Untitled")

ControlSend($handle, '', 'Edit1', 'Text')

Just don't put the handle in the second parameter (text), otherwise it looks for some text in the window that has the handle you're passing it.

*Edit: Nevermind, I think I understand now, you want to send the text to the window, but no specific control, is that right? In that case, I have had some success with just leaving the ControlID parameter blank, but I may have had the window in focus first (which I suppose defeats the entire purpose, as I could have then just used Send()). Sorry.

Edited by Saunders
Link to comment
Share on other sites

No your first was correct; i am using the handle and just replaced it with the handle, using the most basic example availible, and that worked. It worked perfectly using this following code, where the handle is simply the result of the handle previously saved in the script..

ControlSend( $handleMaster, "", "Edit1", $keys )

This works great on notepad, however thats because the textbox is the class Edit1. Here comes in the problem, what if i dont have such a classname to work with? I'm currently trying to send the keys into a different program but in failure, basicly because i dont have a controlname. Its also not possible to get one using the autoit tool.. isnt there some kind of way to send a key globally?

__

What i mean with this is the following: Send() is just sending keys into whatever is focused. I'd like to use a similar way, to whatever is focused in the program, but then using a handle to send it to. The program should just place the text whatever it has activated. I tried leaving the ControlID blank but that just resulted into a stack overflow (because it didnt find a window properly). Any way to send it on some kind of global mode? Thanks in advance.

Edit // Fixed stack overflow, my fault. Just not finding window yet.

Edited by Blastradius
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...