Jump to content

Why Does ControlClick Unfocus other windows!


Recommended Posts

when I use ControlClick, My current active window lose its focus (Sometimes)!

Is it natural or Is this a bug or something?

 

And I know this workaround, but it repeatedly change focus of my windows (Annoying)

$window = WinGetHandle("")
ControlClick('iTools模拟器2','','CHWindow1','left',1,80,40)
WinActivate($window)

 

And i used these functions, but same problem!

DllCall("user32.dll","int","SendMessage","hwnd",WinGetHandle($Window),"int",$WM_MOUSE,"int",0,"long",_MakeLong($X, $Y))

 

---

If it helps, I'm on latest Autoit version and win 10 x64

Edited by HamidZaeri
Link to comment
Share on other sites

  • Moderators

If you simply sit and let the script run, without doing anything else, does the active window still lose focus?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

8 minutes ago, JLogan3o13 said:

If you simply sit and let the script run, without doing anything else, does the active window still lose focus?

Yep

Here is part of my codes:

$hWin[$i] = WinGetHandle($winid[$en[0]+$i],'sub')
    $hCtr[$i] = ControlGetHandle($hWin[$i],'','CHWindow1')

    Switch PixWinColor(13,54,$hWin[$i])
    Case 0x3281C6
        ControlClick($hWin[$i],'',$hCtr[$i],'left',2,80,40)
        ControlSend($hWin[$i],'',$hCtr[$i],$apn[$cn[0]+Mod($i+$j,$cn[1])])
        Sleep(20/$rate)
        ControlClick($hWin[$i],'',$hCtr[$i],'left',2,80,55)
        For $h = $cn[2] To $cn[2]+$cn[1]
            If StringLeft($apn[$cn[0]+Mod($i+$j,$cn[1])],6)=StringLeft($apn[$cn[0]+Mod($i+$j+$h,$cn[1])],6) And $apn[$cn[0]+Mod($i+$j,$cn[1])]<>$apn[$cn[0]+Mod($i+$j+$h,$cn[1])] Then
                ControlSend($hWin[$i],'',$hCtr[$i],$apn[$cn[0]+Mod($i+$j+$h,$cn[1])])
                ExitLoop
            EndIf
        Next
        Sleep(20/$rate)
        ControlClick($hWin[$i],'',$hCtr[$i],'left',2,80,70)
        ControlSend($hWin[$i],'',$hCtr[$i],$fee[0])
        Sleep(10/$rate)
        ControlClick($hWin[$i],'',$hCtr[$i],'left',1,7,191)

And afaik it's not related to ControlSend (tested)

Link to comment
Share on other sites

  • Moderators

ControlClick doesn't steal focus either. How about posting all of your code, or at least a runnable reproducer, so we can test, along with an explanation of what you're trying to do? We can't do anything with this snippet.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

On 6/5/2018 at 5:32 PM, JLogan3o13 said:

ControlClick doesn't steal focus either. How about posting all of your code, or at least a runnable reproducer, so we can test, along with an explanation of what you're trying to do? We can't do anything with this snippet.

ControlClick is responsible for losing focus, Because when I remove them there's no problem!

It is all the script (I have removed some sensitive stuff).

Actually I use another script to ShellExecute This one .

;If TimerDiff($time[$i]) < 200/$rate Then ContinueLoop
    Switch PixWinColor(13,54,$hWin[$i])
    Case 0x3281C6 ;Cards
        For $h = 0 To 10
            If PixWinColor(13,54,$hWin[$i])=0x2276BD Then ContinueCase
            If $err[$i][2] = 0 Then ExitLoop
            Sleep(15/$rate)
        Next
        ;$winid[0] = WinGetHandle('')
        If PixWinColor(73,107,$hWin[$i])=0xD4E4F3 Then ControlClick($hWin[$i],'',$hCtr[$i],'left',1,7,191)
        ;ControlClick($hWin[$i],'',$hCtr[$i],'left',2,80,40)
        ControlSend($hWin[$i],'',$hCtr[$i],$card[$cn[0]+Mod($i+$j,$cn[1])])
        Sleep(20/$rate)
        ControlClick($hWin[$i],'',$hCtr[$i],'left',2,80,55)
        For $h = $cn[2] To $cn[2]+$cn[1]
            If StringLeft($card[$cn[0]+Mod($i+$j,$cn[1])],6)=StringLeft($card[$cn[0]+Mod($i+$j+$h,$cn[1])],6) And $card[$cn[0]+Mod($i+$j,$cn[1])]<>$card[$cn[0]+Mod($i+$j+$h,$cn[1])] Then
                ControlSend($hWin[$i],'',$hCtr[$i],$card[$cn[0]+Mod($i+$j+$h,$cn[1])])
                ExitLoop
            EndIf
        Next
        If $i = $en[1] - 1 Then $cn[2] = Mod($cn[2],$cn[1]-1) + 1
        Sleep(20/$rate)
        ControlClick($hWin[$i],'',$hCtr[$i],'left',2,80,70)
        ControlSend($hWin[$i],'',$hCtr[$i],$fee[0])
        Sleep(10/$rate)
        If PixWinColor(145,170,$hWin[$i]) <> 0xFAFAFA Then
            ControlClick($hWin[$i],'',$hCtr[$i],'left',1,7,191)
            $fee[0] += 1
            $err[$i][2] += 1
            ResetErr(2)
            If $err[$i][2] > 2 And Mod(100*$rate,10) = 2 Then
                SwitchApp()
                ResetErr(-1)
            EndIf
        ElseIf TimerDiff($time[$i]) > 1500/$rate Then
            $time[$i]=TimerInit()+0*Run($avmdir&'tools\adb.exe -s '&$adbid[$en[0]+$i]&' shell am start -S -n '&$appid[$ap[0]+Mod($i+$j+$aps[$i],$ap[1])]&'/activities.SplashActivity --activity-clear-task','',@SW_HIDE)
        EndIf
        ;WinActivate($winid[0])

 

Edited by HamidZaeri
Link to comment
Share on other sites

5 minutes ago, Juvigy said:

The control that you are clicking is stealing the focus. Some controls do it because they perform some actions at the background. It is normal.

Ah, you're right.

Any way to stop programs (controls) stealing focus?

Link to comment
Share on other sites

22 hours ago, Bert said:

You are running an uninstall routine if I'm reading the code right. Is it possible to use command line switches with the uninstaller?

Thanks for your attention but no, it's not related to installation!

Link to comment
Share on other sites

On 6/6/2018 at 3:52 PM, Juvigy said:

You can return the focus to the desired window with Autoit right after the control click.

You can also try making the window minimized,invisible or the control enabled/disabled and so on.

ControlDisable did the trick

 

Edited by HamidZaeri
Link to comment
Share on other sites

  • 1 month later...
On 6/7/2018 at 10:05 PM, HamidZaeri said:

ControlDisable did the trick

 

Stealing focus solved by disable control, but I have another problem:

I lose mouse key hold after ControlClick, (I can't  drag with mouse because mouse keys get released right after ControlClick)

I know ControlClick is not responsible for that (Right?) but is there any workaround? Or what should I Google?

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