Buffo Posted December 9, 2005 Share Posted December 9, 2005 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 9, 2005 Moderators Share Posted December 9, 2005 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. Link to comment Share on other sites More sharing options...
Buffo Posted December 9, 2005 Author Share Posted December 9, 2005 Good idea! But unfortunately _IsPressed doesn't respond on right-clicking... Other ideas? Regards, Buffo Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 9, 2005 Moderators Share Posted December 9, 2005 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. Link to comment Share on other sites More sharing options...
Buffo Posted December 9, 2005 Author Share Posted December 9, 2005 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 9, 2005 Moderators Share Posted December 9, 2005 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). expandcollapse popup#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 krasnoshtan 1 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. Link to comment Share on other sites More sharing options...
seandisanti Posted December 9, 2005 Share Posted December 9, 2005 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). expandcollapse popup#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) EndFuncinstead 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... krasnoshtan 1 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 9, 2005 Moderators Share Posted December 9, 2005 Nice one cameronsdad, I had forgotten about those . 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. Link to comment Share on other sites More sharing options...
seandisanti Posted December 9, 2005 Share Posted December 9, 2005 Nice one cameronsdad, I had forgotten about those .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. krasnoshtan 1 Link to comment Share on other sites More sharing options...
Buffo Posted December 11, 2005 Author Share Posted December 11, 2005 @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 Link to comment Share on other sites More sharing options...
krasnoshtan Posted August 31, 2020 Share Posted August 31, 2020 On 12/9/2005 at 9:49 PM, seandisanti said: SmOke_N said: Nice one cameronsdad, I had forgotten about those . 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! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 31, 2020 Moderators Share Posted August 31, 2020 (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 August 31, 2020 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! Link to comment Share on other sites More sharing options...
Recommended Posts