Jump to content

Recommended Posts

Posted (edited)

scenario:

I compile this code...

GUICreate('mytest', 300, 100)
$button = GUICtrlCreateButton('button', 130, 40)
GUISetState()

While 3
    Switch GUIGetMsg()
        Case $button
            MsgBox(0, 'Button', 'Pressed')
        Case -3
            Exit
    EndSwitch
WEnd

...and execute the compiled script.

Then run this code from scite...

ControlClick('mytest', '', '[CLASS:Button; INSTANCE:1]')

... and this is where it's odd.

The GUI button will only be clicked once in every three attempts of running the script.

First run activates the GUI, second does nothing and the third clicks the button, and then we're full circle.

Is my computer going mad, or can anyone reproduce same?

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

  • Moderators
Posted

JohnOne,

I get the same "1 in 3" result as you. The Help file mentions that ControlClick does need some controls to be in the active window - and if I add a WinActivate("mytest") line first the button fires every time, so this must be one of them. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

Hmm, so it does, wonder why the third time fires without it being activated first though.

EDIT:

well once winactivate has been used, and you comment it out, it fires every time too.

EDIT:

that is of course until the gui exe is restarted

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted (edited)

I'm beginning to suspect a bug in ControlClick()

The above test show how odd it is, and I now doubt it's GUI oddness, cause I've never had an issue clicking a simple au3 button before.

Repeat the test but this time ensure the test GUI is minimized and the click works every time.

EDIT:

Having said that, It's also possible that a windows update has broken it.

I'd be interested to hear if this weirdness occurs in xp and vista, I'm on 7 x86.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted (edited)
  On 3/16/2014 at 5:25 PM, JohnOne said:

Hmm, so it does, wonder why the third time fires without it being activated first though.

 

Try this:

$hwnd = GUICreate('mytest', 300, 100)
$button = GUICtrlCreateButton('button', 130, 40)
WinSetOnTop($hwnd,'',1)
GUISetState()

While 3
    Switch GUIGetMsg()
        Case $button
            MsgBox(0, 'Button', 'Pressed')
        Case -3
            Exit
    EndSwitch
WEnd

now you can better see what happen.

ps.

Win7Pro x64 - the same results

EDIT: typo

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

  On 3/17/2014 at 3:06 PM, JohnOne said:

mLipok does it work as it should if GUI is minimized?

 

Yes

 

  On 3/16/2014 at 5:19 PM, Melba23 said:

JohnOne,

I get the same "1 in 3" result as you. The Help file mentions that ControlClick does need some controls to be in the active window - and if I add a WinActivate("mytest") line first the button fires every time, so this must be one of them. ;)

M23

 

and....

  On 3/17/2014 at 2:39 PM, JohnOne said:

I'm beginning to suspect a bug in ControlClick()

 

This is not problem with WinActive state.

This is a problem with ControlClick

try this:

$hwnd = GUICreate('mytest', 300, 100)
$button = GUICtrlCreateButton('button', 130, 40)
WinSetOnTop($hwnd,'',1)
GUISetState()

While 3
    Switch GUIGetMsg()
        Case $button
            MsgBox(0, 'Button', 'Pressed')
        Case -3
            Exit
    EndSwitch
WEnd

and this:

ControlFocus('mytest', '', '[CLASS:Button; INSTANCE:1]')
ControlClick('mytest', '', '[CLASS:Button; INSTANCE:1]')

How you can see now it works every time regardless of whether the window is active.

For me it deserves to be Tracked as Feature Request, or even as a Bug.

 

EDIT:

TrackTicket: ... because if properly indicated on the Button, regardless of the status window ControlClick should work properly, yet in effect after the "click" , focus will be set.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 3/17/2014 at 3:24 PM, JohnOne said:

But what if a windows update has caused the issue, I don't think it would qualify as a bug.

So only feature request.

My opinion is that if someone wants to click using this function, the function should click properly in every situation, especially since the end result will be exactly the same if I physically click with the mouse.

Edit:

unless, the current effect is intentional, maybe it has to serve some specific cases.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

try this:

#include <GUIConstantsEx.au3>

$hwnd = GUICreate('mytest', 300, 100)
$button = GUICtrlCreateButton('button', 40, 40)
$button2 = GUICtrlCreateButton('button2', 100, 40)
$TrayTip = GUICtrlCreateCheckbox('TrayTip ?', 150, 40)
WinSetOnTop($hwnd, '', 1)
GUISetState()

Global $iCount = 0
GUICtrlSetState($button2, $GUI_FOCUS)

While 3
    Switch GUIGetMsg()
        Case $button
            $iCount += 1
            If GUICtrlRead($TrayTip) = $GUI_CHECKED Then
                TrayTip('Button', 'Pressed #' & $iCount, 1)
            Else
                MsgBox(0, 'Button', 'Pressed #' & $iCount)
            EndIf
        Case -3
            Exit
    EndSwitch
WEnd

You will notice that with TrayTip this problem do not appear.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

  On 3/17/2014 at 3:48 PM, mikell said:

We can assume that this issue is known since ages as we always could read in the helpfile

"Use the WinActivate() function to force the control's window to the top before using ControlClick()."

The fact that this is known since ages, do not mean this is intentional.

 

 

  On 3/17/2014 at 3:55 PM, JohnOne said:

I don't believe so, this is new and unexpected behaviour to me.

 

I'm aware that some controls need focus, but I've used this many times on the very controls I'm trying it on now, and it's acting all weird.

 

I found something interesting and another one   ;)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

  On 3/18/2014 at 9:01 PM, mLipok said:

The fact that this is known since ages, do not mean this is intentional.

Oh I agree !  :)

But if the only answer is the use of WinActivate, that probably means that the solution depends on different various circumstances, so the only reliable (?) way should be - as you said before - to include a ControlFocus into the ControlClick command

BTW thanks for the 2 funny links  :D

Posted
  On 3/18/2014 at 10:01 PM, mikell said:

BTW thanks for the 2 funny links  :D

 

I wonder if JohnOne also considers it "funny".

I hope he have a sense of humor.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...