Jump to content
Buffo

Different functions for left/right mouse click on gui control

Recommended Posts

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() .


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.

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


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.

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

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.

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...

Share this post


Link to post
Share on other sites

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


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.

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.

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
On 12/9/2005 at 9:49 PM, seandisanti said:
SmOke_N said:

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

thanks, i was thinking of making a udf...

Hello! Can you please help to differentiate not just the whole GUI mouse click, but exactly on different labels/button/etc. I would highly appreciate such an UDF or example (and many of coders, I think)!­čśâ

Thank you for your time!

Share this post


Link to post
Share on other sites
Posted (edited)

@krasnoshtan did you happen to notice this thread is 15 years old?? Please don't resurrect very old threads, as the language has changed multiple times in the last decade and a half. You are better off starting a new thread, explaining in detail what you are trying to do, and what problems you are having.

Be sure you are showing your code and what you have tried on your own; the amount of help you get will be directly related to the amount of effort you show ;)

 

Edited by JLogan3o13

"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!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...