Jump to content
Sign in to follow this  
Grantson

Problem with _isPressed in a loop

Recommended Posts

Grantson

I have a script witch has a simple gui with a go button

when the go button is clicked it uses _ispressed to wait for a right click then calls a function to copy the loaction of an image in firefox

the 1st time through the loop it works perfectly if i press the button again and right click an image it gets asfar as the while loop and completly ignores the mouse click

CODE
#include <Misc.au3>

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

$Form1 = GUICreate("Pic Viewer", 327, 129, 193, 125, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))

$Button1 = GUICtrlCreateButton("&Go", 51, 71, 89, 25, 0)

$Button2 = GUICtrlCreateButton("E&xit", 180, 71, 89, 25, 0)

$dll = DllOpen("user32.dll")

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Button1

While 1

Sleep ( 250 )

If _IsPressed("02", $dll) Then

copy_pic()

ExitLoop

EndIf

WEnd

DllClose($dll)

Case $Button2

Exit

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

Func copy_pic()

sleep(250)

send("o")

EndFunc

this is probably primative as hell so if anyone can help or shed light on a more efficient method then please do

Thanks

Grant

Share this post


Link to post
Share on other sites
smashly

I'm not sure if it's the reason for your problem, but I notice you open the dll before the first main While loop..

Then in the 2nd While loop after pressing the button your closing the dll..

From that point on the dll open never gets called again.

Maybe leave the dll open untill you exit the script or open and close the dll each time the button is pressed.

Edited by smashly

Share this post


Link to post
Share on other sites
fctd

Try this (not tested)

#include <Misc.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Pic Viewer", 327, 129, 193, 125, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
$Button1 = GUICtrlCreateButton("&Go", 51, 71, 89, 25, 0)
$Button2 = GUICtrlCreateButton("E&xit", 180, 71, 89, 25, 0)

;$dll = DllOpen("user32.dll")

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $Button1
            $dll = DllOpen("user32.dll")
            While 1
                Sleep ( 250 )
                If _IsPressed("02", $dll) Then
                    copy_pic()
                    ExitLoop
                EndIf
            WEnd
            DllClose($dll)
        Case $Button2
            Exit
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func copy_pic()
    sleep(250)
    send("o")
EndFunc

*edit* Sorry smashly, didn't saw youre reply. *

Edited by fctd

[list][font="Century Gothic"]If nothing is certain, everything is possible.[/font][/list][font="Century Gothic"]Experience is something you get, just after you need it.[/font]

Share this post


Link to post
Share on other sites
Grantson

I'm not sure if it's the reason for your problem, but I notice you open the dll before the first main While loop..

Then in the 2nd While loop after pressing the button your closing the dll..

From that point on the dll open never gets called again.

Maybe leave the dll open untill you exit the script or open and close the dll each time the button is pressed.

Spot on

never i thought it might be something like that but having it nested in the variable $dll i never noticed it

joys of a sunday afternoon lol

thanks :)

Share this post


Link to post
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
Sign in to follow this  

×