Sign in to follow this  
Followers 0
Buffo

Different functions for left/right mouse click on gui control

10 posts in this topic

Hi ;-)

Is it possible to call different functions on clicking left mouse button or clicking right mouse button on a gui control?

In my script I want to change the data of a label control in this way: When I left-click with the mouse on it it should increase, when I right-click on it it should decrease.

Eather it is very simple but I am too stupid or it isn't possible ;-) I searched for it in this forum and in beta help-file but I didn't get the solution.

Hope you can help :-)

Regards,

Buffo

Share this post


Link to post
Share on other sites



A possible solution might be a combination of IsPressed() and GUICtrlSetData() .


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Good idea!

But unfortunately _IsPressed doesn't respond on right-clicking...

Other ideas?

Regards,

Buffo

Share this post


Link to post
Share on other sites

Good idea!

But unfortunately _IsPressed doesn't respond on right-clicking...

Other ideas?

Regards,

Buffo

It doesn't? Is the below only if the Right is your Primary?

Function Reference

_IsPressed

--------------------------------------------------------------------------------

Check if key has been pressed

#Include <Misc.au3>

_IsPressed($s_hexKey[, $v_dll = 'user32.dll'])

Return Value

Success: Returns 1 if true.

Failure: Returns 0 if false.

Remarks

01 Left mouse button

02 Right mouse button


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Certainly you can check if right mouse is pressed but the "Click"-event of the control does not respond on.

I have to try something like this:

#include <_IsPressed.au3>
Opt("GuiOnEventMode", 1)
GuiCreate("Test", 200, 200)
$label = GuiCtrlCreateLabel("50", 30, 30, 80, 30)
GuiCtrlSetOnEvent($label, "LeftClick")
GuiSetState(@SW_SHOW)

While 1
If _IsPressed("02") Then RightClick()
Sleep(500)
WEnd

Func LeftClick()
MsgBox(0, "Info", "LeftClick")
EndFunc

Func RightClick()
$pos = MouseGetPos()
If $pos[0] > 30 And $pos[0] < 110 And $pos[1] > 30 And $pos[1] < 60 Then MsgBox(0, "Info", "RightClick On Label")
EndFunc

Regards,

Buffo

Share this post


Link to post
Share on other sites

Here try this: (You will need Beta to use this, you can copy and run my signature script to get it if you don't have it).

#include <GUIConstants.au3>
#include <Misc.au3>
Opt("GUICoordMode", 1)
Opt("WinTitleMatchMode", 1)
Opt("MouseCoordMode", 2)
$MAIN_GUI = GuiCreate("Test", 200, 200)
$LABEL = GuiCtrlCreateLABEL("50", 30, 30, 80, 30)

GuiSetState(@SW_SHOW)

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then Exit
    If _IsPressed(01) Then
        $pos = MouseGetPos()
        If $pos[0] > 30 And $pos[0] < 110 And $pos[1] > 30 And $pos[1] < 60 Then
            LeftClick()
        EndIf
    EndIf
    If _IsPressed(02) Then
        $pos = MouseGetPos()
        If $pos[0] > 30 And $pos[0] < 110 And $pos[1] > 30 And $pos[1] < 60 Then
            RightClick()
        EndIf
    EndIf
    Sleep(10)
WEnd

Func LeftClick()
;MsgBox(0, "Info", "LeftClick")
    $RANDOM = RANDOM(1, 1000, 1)
    GUICtrlSetData($LABEL, $RANDOM)
EndFunc

Func RightClick()
;MsgBox(0, "Info", "RightClick On LABEL")
    $RANDOM = RANDOM(1, 1000, 1)
    GUICtrlSetData($LABEL, $RANDOM)
EndFunc

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Here try this: (You will need Beta to use this, you can copy and run my signature script to get it if you don't have it).

#include <GUIConstants.au3>
#include <Misc.au3>
Opt("GUICoordMode", 1)
Opt("WinTitleMatchMode", 1)
Opt("MouseCoordMode", 2)
$MAIN_GUI = GuiCreate("Test", 200, 200)
$LABEL = GuiCtrlCreateLABEL("50", 30, 30, 80, 30)

GuiSetState(@SW_SHOW)

While 1
    $MSG = GUIGetMsg()
    If $MSG = -3 Then Exit
    If _IsPressed(01) Then
        $pos = MouseGetPos()
        If $pos[0] > 30 And $pos[0] < 110 And $pos[1] > 30 And $pos[1] < 60 Then
            LeftClick()
        EndIf
    EndIf
    If _IsPressed(02) Then
        $pos = MouseGetPos()
        If $pos[0] > 30 And $pos[0] < 110 And $pos[1] > 30 And $pos[1] < 60 Then
            RightClick()
        EndIf
    EndIf
    Sleep(10)
WEnd

Func LeftClick()
;MsgBox(0, "Info", "LeftClick")
    $RANDOM = RANDOM(1, 1000, 1)
    GUICtrlSetData($LABEL, $RANDOM)
EndFunc

Func RightClick()
;MsgBox(0, "Info", "RightClick On LABEL")
    $RANDOM = RANDOM(1, 1000, 1)
    GUICtrlSetData($LABEL, $RANDOM)
EndFunc
instead of using _isPressed() you could just watch for the events - $GUI_EVENT_PRIMARYDOWN and $GUI_EVENT_SECONDARYDOWN

while 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_PRIMARYDOWN
msgbox(0,"Click","Left Click")
Case $msg = $GUI_EVENT_SECONDARYDOWN
msgbox(0,"Click","Right Click")
EndSelect

and just call your functions instead of msgbox'ing which button was clicked...


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Nice one cameronsdad, I had forgotten about those :P.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Nice one cameronsdad, I had forgotten about those :P.

thanks, i was thinking of making a udf to watch for them outside of an autoit gui, but i don't have the platform sdk at work anymore, nor internet access to look up what DLL's i'd have to call to watch for the events.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

@SmOke N: Thx for your Script. I have adjusted it to my needs and it works like a harm :-)

@cameronsdad: Nice idea. Maybe I'll give it a chance.

Regards,

Buffo

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  
Followers 0