Jump to content

Issue with the window focus


Denver
 Share

Recommended Posts

Hello world !

Herm...

I try to have a script running a game ( "Dofus" ), and when the mouse cursor is on the login input area, it sends it from an array.

But the issue is when the focus should be at the right place ( the games' window ), there's a weird activation while mouse come over some text on IE (for example).

;var examples
$GameName = "Dofus"
$prgChemin = "C:\Program Files\"
$prgNom = "Dofus.exe"
$compteBis = 0
$aLog [ 0 ] = "test"
$aLog [ 1 ] = "Tralala-lalère{TAB}SomethingLikeThat"

;the function
ShellExecute ( $prgNom, "", $prgChemin )
Do
    Do
        sleep ( 20 )
    Until   MouseGetCursor () = 5
    If  WinActive ( $GameName ) Then    MouseClick ( "left" )
    Sleep ( 20 )
Until   WinActive ( $GameName )
WinSetTitle ( $GameName, "", $GameName & " - " & $aLog [ $compteBis ] )
Send ( $aLog[ $compte + 1 ] )

I've tried the "WinWaitActive()" function instead of the Do..Until (and both working), but no way to get really sure that informations are really sent on the "Dofus" window.

Someone helping me ?

Edit : the issue could be something else than focus.. After testing, the IE's window called "DofusLog" ( according to the name of my script ) is in case, but not "google"..

So, the question would be now : "How make sure this is the name of the good active window that is targetted ?"

Edited by Denver
Link to comment
Share on other sites

;====================================================
; Returns the Handle of GUI the mouse is over.
;http://www.autoitscript.com/forum/index.php?s=&showtopic=19370&view=findpost&p=444962
;   
Func GetHoveredHwnd()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(), "long", MouseGetPos())
    If IsArray($iRet) Then
        MsgBox(0,"",$iRet[0] & "    " & $iRet[1] & "    " & $iRet[2] & "    " & HWnd($iRet[0] ))
        Return  HWnd($iRet[0])
    else
        Return SetError(1, 0, 0)
    EndIf
EndFunc

Gets you a handle to the window based on the mouse pos.

$handle = GetHoveredHwnd()

WinActive($handle)

That might help

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Yeah, thanks a lot !

I was thinking (desperately...) how to have or make such function.

Now, the other side of the problem is to now the handle of the good window.

Coming back when I've found ! (or when I'm totally depressive. :c )

D.

Edited by Denver
Link to comment
Share on other sites

Greetings for the WinGetHandle search in auto-it help : I've found better.

" AutoItSetOption ( "WinTitleMatchMode", 3 ) " that force the text to exactly match, wathever happens.

Now, the script correcly running : ( lightly updated for some Dofusian's gamers that doesn't know about my DofusLog )

;var examples
$GameName = "Dofus  "
$prgChemin = "C:\Program Files\"
$prgNom = "Dofus.exe"
$compteBis = 0
$aLog [ 0 ] = "test"
$aLog [ 1 ] = "Tralala-lalère{TAB}SomethingLikeThat"

;the function
ShellExecute ( $prgNom, "", $prgChemin )
AutoItSetOption ( "WinTitleMatchMode", 3 ) ;that is what I was missing of. :P
Do
    Do
        sleep ( 20 )
    Until   MouseGetCursor () = 5
    If  WinActive ( $GameName )   Then   MouseClick ( "left" )
    Sleep ( 20 )
Until   WinActive ( $GameName )
WinSetTitle ( $GameName, "", $GameName & " - " & $aLog [ $compteBis ] )
Send ( $aLog[ $compte + 1 ] )

Thanks for such a fast help !

Edited by Denver
Link to comment
Share on other sites

Nps. Yeah WinTitleMatchMode is important. I do rate WinGetHandle but gave you GetHoveredHwnd as you said you were having troubles.

If you are using GetHoveredHwnd, I should tell you - MouseCoordMode play a role else don't worry about it.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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