rdwray Posted June 6, 2011 Share Posted June 6, 2011 I am trying to do something really simple and I cannot find anything that can handle the problem - yes I have been searching for hours in the forum. I just want to be able to trap the mousedown event on a button and return the button ID. In AHK that can be done with MouseGetPos; does AutoIt have anything that will do the job? thanks... “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
picea892 Posted June 6, 2011 Share Posted June 6, 2011 Is this an AU3 created GUI or a windows GUI? GUIGetCursorInfo for an AU3 window For a windows GUI use this function (it returns a handle) Func _ControlGetHovered() Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) If Not IsArray($aRet) Then Return SetError(1, 0, 0) Return HWnd($aRet[0]) EndFunc Link to comment Share on other sites More sharing options...
rdwray Posted June 6, 2011 Author Share Posted June 6, 2011 (edited) Is this an AU3 created GUI or a windows GUI? GUIGetCursorInfo for an AU3 window For a windows GUI use this function (it returns a handle) Func _ControlGetHovered() Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) If Not IsArray($aRet) Then Return SetError(1, 0, 0) Return HWnd($aRet[0]) EndFunc I am working with AU3 script only. I don't mind integrating something, but I am talking about over 60 controls. EDIT: AU3 seems to only recognize MouseUp and not MouseDown and this is the hangup. Edited June 6, 2011 by rdwray “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
lvlrdka22 Posted June 6, 2011 Share Posted June 6, 2011 @GUI_CtrlId returns the last-clicked control, if you are using GUI event mode. Link to comment Share on other sites More sharing options...
BrewManNH Posted June 6, 2011 Share Posted June 6, 2011 Maybe a better explanation of what it is you're trying to accomplish would help? If you want to know which button on your GUI has been pressed, look at either GUIGetMsg (message loop mode) or GUICtrlSetOnEvent (control event mode) as a start. Otherwise, I'm not exactly sure what it is you're looking to get. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rdwray Posted June 6, 2011 Author Share Posted June 6, 2011 Maybe a better explanation of what it is you're trying to accomplish would help? If you want to know which button on your GUI has been pressed, look at either GUIGetMsg (message loop mode) or GUICtrlSetOnEvent (control event mode) as a start. Otherwise, I'm not exactly sure what it is you're looking to get.I have a 2 state button and 2 images. I want to display a normal state image and a pressed state image. “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
guinness Posted June 6, 2011 Share Posted June 6, 2011 What about GUIGetCursorInfo? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
rdwray Posted June 6, 2011 Author Share Posted June 6, 2011 What about GUIGetCursorInfo? I think $array[4] may be the answer, I don't know why I didn't see that when I was looking at the function, going for an eye check up. thanks... “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
BrewManNH Posted June 6, 2011 Share Posted June 6, 2011 I have a 2 state button and 2 images. I want to display a normal state image and a pressed state image.Ok, I get it now. You might want to check out which does what you're looking for. You can either use his UDF or look at the code to see how it's done. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rdwray Posted June 6, 2011 Author Share Posted June 6, 2011 Here is what I ended up with. The one thing that is required in this situation is that you have to know the ControlID.#include <Misc.au3> $dll = DllOpen("user32.dll") Global $ctrl = GUIGetCursorInfo() If $ctrl[4] = 4 And _IsPressed(01, $dll) Then GUICtrlSetImage($butMoveFirst, @ScriptDir & '\Images\MoveFirstDn.bmp') Else GUICtrlSetImage($butMoveFirst, @ScriptDir & '\Images\MoveFirstUp.bmp') EndIf “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
rdwray Posted June 7, 2011 Author Share Posted June 7, 2011 Why would the following "Tooltip" cause the GUI to close if it loses focus?#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <GUIScrollBars.au3> #include <ScrollBarConstants.au3> #include <Misc.au3> Global $hGuiWin Global $pressed, $ctrl, $dll = DllOpen("user32.dll") Main() Func Main() $hGuiWin = GUICreate ("Contacts DB", 900, 750) GUISetBkColor (0x000000, $hGuiWin ) GUISetState(@SW_SHOW) While 1 If _IsPressed(01, $dll) And $pressed = 0 Then $pressed = 1 ElseIf Not _IsPressed(01, $dll) Then $ctrl = GUIGetCursorInfo() $pressed = 0 EndIf ToolTip($ctrl[4]) ; CAUSES WINDOW TO CLOSE WHEN LOSING FOCUS. ; ToolTip("tooltip") ; DOES NOT CAUSE CRASH. Switch GUIGetMsg(0) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc ; Main() “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
rdwray Posted June 7, 2011 Author Share Posted June 7, 2011 Found a work around in that if I use the window handle like this GUIGetCursorInfo($hGuiWin) it works. Don't know, but it looks like a bug in AU3. “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
BrewManNH Posted June 7, 2011 Share Posted June 7, 2011 It's probably crashing because the array $ctrl is no longer an array because the GUIGetCursorInfo isn't over an AutoIT GUI.From the help fileThe mouse cursor position is successful only on an window created by a GUICreate. When no winhandle it will be successful if the GUI Windows is active. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rdwray Posted June 7, 2011 Author Share Posted June 7, 2011 It's probably crashing because the array $ctrl is no longer an array because the GUIGetCursorInfo isn't over an AutoIT GUI. From the help file Ok, help me out here. If the window isn't active, then the tooltip is not available and not active. Why would the GUI close? I gave this a try and it still crashes:If WinActive("Contacts DB") Then ToolTip($ctrl[4] & " " ) Else ToolTip("") EndIf “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
BrewManNH Posted June 7, 2011 Share Posted June 7, 2011 What's the error message you're receiving when it crashes? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rdwray Posted June 7, 2011 Author Share Posted June 7, 2011 What's the error message you're receiving when it crashes? This:ToolTip($ctrl[4] & " " ) ToolTip($ctrl^ ERROR “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
BrewManNH Posted June 7, 2011 Share Posted June 7, 2011 Try this:If IsArray($ctrl) Then ToolTip($ctrl[4]) ; CAUSES WINDOW TO CLOSE WHEN LOSING FOCUS. EndifUntested If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rdwray Posted June 7, 2011 Author Share Posted June 7, 2011 Try this: If IsArray($ctrl) Then ToolTip($ctrl[4]) ; CAUSES WINDOW TO CLOSE WHEN LOSING FOCUS. Endif Untested Still crashes. “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
BrewManNH Posted June 7, 2011 Share Posted June 7, 2011 What is the EXACT error message that you get when it crashes, what you posted previously was only a tiny part of it. Without the full error message it's going to be very hard to trouble shoot what's happening. Also, make sure you haven't changed the code around the error message area too much from what's posted, if you have changed it, please repost the script with the changes so that we're all working from the same base. Thanks. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
rdwray Posted June 7, 2011 Author Share Posted June 7, 2011 What is the EXACT error message that you get when it crashes, what you posted previously was only a tiny part of it. Without the full error message it's going to be very hard to trouble shoot what's happening. Also, make sure you haven't changed the code around the error message area too much from what's posted, if you have changed it, please repost the script with the changes so that we're all working from the same base. Thanks. “No other God have I but Thee; born in a manger, died on a tree.” Martin Luther Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now