Jump to content

Unexpected behavior


Recommended Posts

Hi forum

I was doing a example for a forum question and happend this...

when i put the debug - consolewrite the program minimizes, when i comment out that line the script dont work how it should work :S its something strange to me, maybe i miss something...

try it in this way, later un - comment the 19 line and see what happend (the consolewrite line)

$gui = GUICreate("MouseClicks Until you hold the mousebutton?", 120, 80)
$radio1 = GUICtrlCreateRadio("Left", 5, 5, 50, 20)
$radio2 = GUICtrlCreateRadio("Right", 5, 30, 50, 20)
Local $a = 2
GUISetState()
While 1
    $gui = GUIGetMsg()
    Switch $gui
        Case -3
            Exit ;$GUI_EVENT_CLOSE
        Case $radio1
            $a = 2
        Case $radio2
            $a = 3
    EndSwitch
    $aMouse = GUIGetCursorInfo()
    If Not @error Then
        If $aMouse[$a] = 1 Then MouseClick("left")
;~          ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : MouseClick("left") = ' & MouseClick("left") & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
    EndIf
WEnd
Edited by monoscout999
Link to comment
Share on other sites

Not sure if I understand what you say the issue is. You do seem to have highlighted the MouseClick() and added it to a debug ConsoleWrite(). The MouseClick happens when the ConsoleWrite() executes so you would have a double left click happening.

Edit: Replaced "debug Msgbox()" with "debug ConsoleWrite()" mistake.

Edited by MHz
Link to comment
Share on other sites

with the msgbox is the same...

Why the evaluation If $aMouse[$a] = 1 Then MouseClick("left") executes the mouseclick as soon i start the script?

Why the windows minimize?

Why the script dont work when the msgbox or the consolewrite are not pressent?

EDIT

$gui = GUICreate("MouseClicks Until you hold the mousebutton?", 120, 80)
$radio1 = GUICtrlCreateRadio("Left", 5, 5, 50, 20)
$radio2 = GUICtrlCreateRadio("Right", 5, 30, 50, 20)
Local $a = 2
GUISetState()
While 1
    $gui = GUIGetMsg()
    Switch $gui
        Case -3
            Exit ;$GUI_EVENT_CLOSE
        Case $radio1
            $a = 2
        Case $radio2
            $a = 3
    EndSwitch
    $aMouse = GUIGetCursorInfo()
    If Not @error Then
        If $aMouse[$a] = 1 Then MouseClick("left")
            consolewrite($aMouse[$a]&@CRLF)
    EndIf
WEnd

Run This... why the console dont return 1 when i hold down the left mousebutton(primary) but it work fine when i check the "Right" radio and use the right mousebutton?

Edited by monoscout999
Link to comment
Share on other sites

Ok, the ConsoleWrite() happens with each loop rapidly as GuiGetMsg() returns often. Your ConsoleWrite is better enclosed in a If structure so it only writes when the value is 1 and nothing else.

This works better to my knowledge of concern.

$gui = GUICreate("MouseClicks Until you hold the mousebutton?", 120, 80)
$radio1 = GUICtrlCreateRadio("Left", 5, 5, 50, 20)
$radio2 = GUICtrlCreateRadio("Right", 5, 30, 50, 20)
Local $a = 2
GUISetState()
While 1
    $gui = GUIGetMsg()
    Switch $gui
        Case -3
            Exit ;$GUI_EVENT_CLOSE
        Case $radio1
            $a = 2
        Case $radio2
            $a = 3
    EndSwitch
    $aMouse = GUIGetCursorInfo()
    If Not @error Then
        If $aMouse[$a] = 1 Then
            MouseClick("left")
            ConsoleWrite($aMouse[$a] & @CRLF)
        EndIf
    EndIf
WEnd

So, I just put the ConsoleWrite within the If...EndIf and only write when your mouse clicks and a radio button is checked. :huh2:

Link to comment
Share on other sites

Ok, the ConsoleWrite() happens with each loop rapidly as GuiGetMsg() returns often. Your ConsoleWrite is better enclosed in a If structure so it only writes when the value is 1 and nothing else.

This works better to my knowledge of concern.

$gui = GUICreate("MouseClicks Until you hold the mousebutton?", 120, 80)
$radio1 = GUICtrlCreateRadio("Left", 5, 5, 50, 20)
$radio2 = GUICtrlCreateRadio("Right", 5, 30, 50, 20)
Local $a = 2
GUISetState()
While 1
    $gui = GUIGetMsg()
    Switch $gui
        Case -3
            Exit ;$GUI_EVENT_CLOSE
        Case $radio1
            $a = 2
        Case $radio2
            $a = 3
    EndSwitch
    $aMouse = GUIGetCursorInfo()
    If Not @error Then
        If $aMouse[$a] = 1 Then
            MouseClick("left")
            ConsoleWrite($aMouse[$a] & @CRLF)
        EndIf
    EndIf
WEnd

So, I just put the ConsoleWrite within the If...EndIf and only write when your mouse clicks and a radio button is checked. :huh2:

you are right i miss that... i think the "why the console dont return 1 when i hold down the left mousebutton(primary) but it work fine when i check the "Right" radio and use the right mousebutton?" question answer is that the aMouse[2] value changes when the mouseclick function send a click(press - release)
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...