Seiln Posted November 15, 2013 Share Posted November 15, 2013 (edited) Hi, So here it goes. I'm working on a Mouse Position Saver ( Which saves coordinates into respective input boxes and later to be saved in an ini file) I am having some trouble finding out how to display the second array without overlapping the first one. I am using a hotkeyset to save the current position of my mouse into x and y input boxes and i'm using guictrlread(x and y input boxes) to transfer the data into a Array. So far I have succesfully managed to display the first set coordinates into my first "save input boxes" but everytime I do the second one it overlaps the first. I am using a button to save coordinates. Some enlightment will be most appreciated. Edited November 15, 2013 by Seiln Link to comment Share on other sites More sharing options...
Rogue5099 Posted November 15, 2013 Share Posted November 15, 2013 For $y = 1 To UBound($aArray, 1) - 1 For $x = 1 To UBound($aArray, 2) - 1 ConsoleWrite($aArray[$y][$x]) Next Next My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Seiln Posted November 15, 2013 Author Share Posted November 15, 2013 Hi, Thank you for posting But could you explain how does that work? Here's the Code I'm using to save the data. If $gMsg = $_CoordSetButton And IsArray($_xCoordCur) = 1 And IsArray($_yCoordCur) = 1 Then $_xCoordCur[0] = GUICtrlRead($_mousepos_x) $_yCoordCur[0] = GUICtrlRead($_mousepos_y) GUICtrlSetData($_xInputSave1, $_xCoordCur[0]) GUICtrlSetData($_yInputSave1, $_yCoordCur[0]) $_xCoordCur[1] = GUICtrlRead($_mousepos_x) $_yCoordCur[1] = GUICtrlRead($_mousepos_y) GUICtrlSetData($_xInputSave2, $_xCoordCur[1]) GUICtrlSetData($_yInputSave2, $_yCoordCur[1]) EndIf Link to comment Share on other sites More sharing options...
l3ill Posted November 15, 2013 Share Posted November 15, 2013 Hi Seiln, Unless you absolutely need the array I would use something like this: #include <File.au3> HotKeySet("{F2}", "_MousePos") While 1 Sleep(1000) WEnd Func _MousePos() Local $file = FileOpen("test.txt", 1) ;file to write to If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf Local $pos = MouseGetPos() MsgBox(0, "Mouse x,y:", $pos[0] & "," & $pos[1], 1) FileWriteLine($file, $pos[0] & " | " & $pos[1]) FileClose($file) EndFunc ;==>_MousePos cya, Bill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
kylomas Posted November 15, 2013 Share Posted November 15, 2013 Seiln, Mouse coordinates occur in pairs which suggests a 2 dimensional array. Rogue5999 was implying this in his earlier post. If I am understanding your problem correctly, you are "overlaying" array elements. The following may have an example of some techniques you can use... expandcollapse popup; *** Start added by AutoIt3Wrapper *** #include <StaticConstants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <WindowsConstants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <ListViewConstants.au3> ; *** End added by AutoIt3Wrapper *** ; *** Start added by AutoIt3Wrapper *** #include <GUIConstantsEx.au3> ; *** End added by AutoIt3Wrapper *** #AutoIt3Wrapper_Add_Constants=n #include <GuiListView.au3> #include <array.au3> #include <date.au3> local $aMousePos[1][3], $idx = 0 local $gui010 = guicreate('Mouse Tracker',400,500,-1,-1,-1) guictrlcreatelabel('Last 10 Clicks',20,10,100,20) local $lv010 = guictrlcreatelistview('x-coord|y-coord|Time Clicked',20,30,250,300,-1, _ bitor($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_SetColumnWidth($lv010,0,50) _GUICtrlListView_SetColumnWidth($lv010,1,50) _GUICtrlListView_SetColumnWidth($lv010,2,150) guictrlcreatelabel('Last X-Coord',20,350,70,20) local $x = guictrlcreateinput('',90,350,30,15) guictrlcreatelabel('Last Y-Coord',20,370,70,20) local $y = guictrlcreateinput('',90,370,30,15) local $btn010 = guictrlcreatebutton('Display Array of All Mouse Clicks',20,460,360,20) guisetstate() while 1 switch guigetmsg() case $GUI_EVENT_CLOSE Exit case $GUI_EVENT_PRIMARYDOWN $aTmp = mousegetpos() ; populate listview _GUICtrlListView_DeleteItem(guictrlgethandle($lv010),$idx) _GUICtrlListView_InsertItem($lv010,$aTmp[0],$idx) _GUICtrlListView_SetItemText($lv010,$idx,$aTmp[1],1) _GUICtrlListView_SetItemText($lv010,$idx,_now(),2) _GUICtrlListView_SetItemSelected($lv010,$idx) $idx += 1 if $idx >= 10 then $idx = 0 ; populate array $aMousePos[ubound($aMousePos)-1][0] = $aTmp[0] $aMousePos[ubound($aMousePos)-1][1] = $aTmp[1] $aMousePos[ubound($aMousePos)-1][2] = _now() redim $aMousePos[ubound($aMousePos)+1][3] ; populate inputboxes guictrlsetdata($x,$aTmp[0]) guictrlsetdata($y,$aTmp[1]) case $btn010 _arraydisplay($aMousePos,'All Mouse Clicks') EndSwitch wend kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jdelaney Posted November 15, 2013 Share Posted November 15, 2013 (edited) Fun...when mouse is where you want it, press Enter(must have the autoit gui as active) on keyboard...you can delete, or add to your own content...you will have to create the Save function...currently, repositioning with each add, since I couldn't get the docking to work: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> AutoItSetOption("MouseCoordMode",1) Global Enum $giData_MouseX, $giData_MouseY, $giData_ButtonDelete, $giData_XLabel, $giData_YLabel, $giData_UBound Global $gaData[1][$giData_UBound] Global $gaCurrent = "" $iDontDockTop = 2+256+512 $iDontDockTop = $GUI_DOCKSIZE+$GUI_DOCKBOTTOM $iControlWidth = 50 $iDeleteWidth = 20 $iControlHeight = 20 $iBuffer = 15 $iButtonHeight = 25 $iGuiWidth = $iBuffer+$iControlWidth+$iBuffer+$iControlWidth+$iBuffer+$iDeleteWidth+$iBuffer $iGuiHeight = $iBuffer+$iButtonHeight+$iBuffer Global $hGui = GUICreate("My GUI",$iGuiWidth,$iGuiHeight) GUISetState(@SW_SHOW) $iCollectData = GUICtrlCreateButton("Collect",$iBuffer,$iBuffer,$iControlWidth,$iButtonHeight,$BS_DEFPUSHBUTTON) GUICtrlSetResizing($iCollectData, $GUI_DOCKSIZE+$GUI_DOCKBOTTOM) $iSaveData = GUICtrlCreateButton("Save",$iBuffer+$iControlWidth+$iBuffer,$iBuffer,$iControlWidth,$iButtonHeight) GUICtrlSetResizing($iSaveData, $GUI_DOCKSIZE+$GUI_DOCKBOTTOM) While 1 $msg = GUIGetMsg() Select Case $msg=$GUI_EVENT_CLOSE ExitLoop Case $msg=$iCollectData $aPos = MouseGetPos() _CreateMousePosControls($aPos) Case $msg=$iSaveData MsgBox(1,1,"create your INI write function base on array = $gaCurrent") Case $msg>$iSaveData _DeleteMousePosControls($msg) EndSelect WEnd GUIDelete() Exit Func _CreateMousePosControls($aCallersMousePos) If Not IsArray($gaCurrent) Then $gaCurrent = $gaData Else ReDim $gaCurrent[UBound($gaCurrent)+1][$giData_UBound] EndIf $aPos = WinGetPos($hGui) WinMove($hGui,"",$aPos[0],$aPos[1],$aPos[2],$aPos[3]+$iBuffer+$iControlHeight) $gaCurrent[UBound($gaCurrent)-1][$giData_MouseX] = $aCallersMousePos[0] $gaCurrent[UBound($gaCurrent)-1][$giData_XLabel] = GUICtrlCreateLabel("X:" & $aCallersMousePos[0],$iBuffer,$iBuffer+$iBuffer*(UBound($gaCurrent)-1)+$iControlHeight*(UBound($gaCurrent)-1),$iControlWidth,$iControlHeight) GUICtrlSetResizing($gaCurrent[UBound($gaCurrent)-1][$giData_XLabel], $iDontDockTop) $gaCurrent[UBound($gaCurrent)-1][$giData_MouseY] = $aCallersMousePos[1] $gaCurrent[UBound($gaCurrent)-1][$giData_YLabel] = GUICtrlCreateLabel("Y:" & $aCallersMousePos[1],$iBuffer+$iControlWidth+$iBuffer,$iBuffer+$iBuffer*(UBound($gaCurrent)-1)+$iControlHeight*(UBound($gaCurrent)-1),$iControlWidth,$iControlHeight) GUICtrlSetResizing($gaCurrent[UBound($gaCurrent)-1][$giData_YLabel], $iDontDockTop) $gaCurrent[UBound($gaCurrent)-1][$giData_ButtonDelete] = GUICtrlCreateButton("-",$iBuffer+$iControlWidth+$iBuffer+$iControlWidth+$iBuffer,-5+$iBuffer+$iBuffer*(UBound($gaCurrent)-1)+$iControlHeight*(UBound($gaCurrent)-1),$iDeleteWidth,$iButtonHeight) GUICtrlSetResizing($gaCurrent[UBound($gaCurrent)-1][$giData_ButtonDelete], $iDontDockTop) _Reposition() EndFunc Func _DeleteMousePosControls($iDelete) For $i = 0 To UBound($gaCurrent)-1 If $gaCurrent[$i][$giData_ButtonDelete] = $iDelete Then GUICtrlDelete($gaCurrent[$i][$giData_XLabel]) GUICtrlDelete($gaCurrent[$i][$giData_YLabel]) GUICtrlDelete($gaCurrent[$i][$giData_ButtonDelete]) $aPos = WinGetPos($hGui) WinMove($hGui,"",$aPos[0],$aPos[1],$aPos[2],$aPos[3]-$iBuffer-$iControlHeight) _ArrayDelete($gaCurrent,$i) _Reposition() ExitLoop EndIf Next EndFunc Func _Reposition () For $i = 0 To UBound($gaCurrent)-1 GUICtrlSetPos($gaCurrent[$i][$giData_XLabel],$iBuffer,$iBuffer+$iBuffer*($i)+$iControlHeight*($i)) GUICtrlSetPos($gaCurrent[$i][$giData_YLabel],$iBuffer+$iControlWidth+$iBuffer,$iBuffer+$iBuffer*($i)+$iControlHeight*($i)) GUICtrlSetPos($gaCurrent[$i][$giData_ButtonDelete],$iBuffer+$iControlWidth+$iBuffer+$iControlWidth+$iBuffer,-5+$iBuffer+$iBuffer*($i)+$iControlHeight*($i)) Next EndFunc Edited November 15, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Rogue5099 Posted November 15, 2013 Share Posted November 15, 2013 (edited) I don't know if this simplifies it or not but here is something small with easy store mouse positions. #include <GuiConstantsEx.au3> HotKeySet('^c', '_DisplayPos') $hGUIMousePos = GUICreate('Mouse Position', 150, 40, -1, -1, -1, 128) GUISetFont(9, 600, '', 'Arial') Global $cLabel = GUICtrlCreateLabel('Ctrl+c to save position', 0, 0, 150, 20, 1) Global $cInput = GUICtrlCreateInput('', 0, 20, 150, 20, 1) GUICtrlSetState($cInput, $GUI_DISABLE) GUISetState(@SW_SHOW) WinSetOnTop($hGUIMousePos, '', 1) AdlibRegister('_GetPos', 50) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE AdlibUnRegister("_GetPos") GUIDelete($hGUIMousePos) Exit Func _GetPos() $aMousePos = MouseGetPos() GUICtrlSetData($cInput, 'X: ' & $aMousePos[0] & ' Y: ' & $aMousePos[1]) EndFunc Func _DisplayPos() GUICtrlSetData($cLabel, GUICtrlRead($cInput)) EndFunc Or another way to store then read the data back. Ctrl+c to save mouse positions: HotKeySet('^c', '_GetPos') $hGUIMousePos = GUICreate('Mouse Position', 160, 120, -1, -1, -1, 128) Global $xInput[6], $yInput[6], $vMousePos For $i = 0 To 5 $xInput[$i] = GUICtrlCreateInput('', 0, $i*20, 75, 20, 1) $yInput[$i] = GUICtrlCreateInput('', 80, $i*20, 75, 20, 1) Next GUISetState(@SW_SHOW) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _GetPos() For $i = 0 To 5 If GUICtrlRead($xInput[$i]) = '' Then $aMousePos = MouseGetPos() GUICtrlSetData($xInput[$i], $aMousePos[0]) GUICtrlSetData($yInput[$i], $aMousePos[1]) If $i = 5 Then For $i = 0 To 5 $vMousePos &= 'X:' & GUICtrlRead($xInput[$i]) & ' Y:' & GUICtrlRead($yInput[$i]) & @CRLF Next MsgBox(0, 'Positions', $vMousePos) Exit EndIf ExitLoop EndIf Next EndFuncI was bored so I did another that stores the data to an Array instead of to GUI controls. In both the last 2 examples you would just have to change to the format you wanted where MsgBox is. This one would be more helpful since its not limited to the number of input boxes. HotKeySet('^c', '_GetPos') $hGUIMousePos = GUICreate('Mouse Position', 160, 120, -1, -1, -1, 128) Global $aMousePos[1], $vMousePos, $nPos = 0 $cDone = GUICtrlCreateButton('Done', 60, 25, 40, 20) $cClear = GUICtrlCreateButton('Clear', 60, 50, 40, 20) $cLabel = GUICtrlCreateLabel('0', 70, 80) GUISetState(@SW_SHOW) Do $msg = GUIGetMsg() If $msg = $cDone Then For $i = 1 To UBound($aMousePos) - 1 $vMousePos &= $aMousePos[$i] & @CRLF Next MsgBox(0, 'Positions', $vMousePos) EndIf If $msg = $cClear Then $aMousePos = 0 $nPos = 0 $vMousePos = '' GUICtrlSetData($cLabel, $nPos) Global $aMousePos[1] EndIf Until $msg = $GUI_EVENT_CLOSE Func _GetPos() ReDim $aMousePos[UBound($aMousePos)+1] $aPos = MouseGetPos() $aMousePos[UBound($aMousePos)-1] = $aPos[0] & ':' & $aPos[1] $nPos += 1 GUICtrlSetData($cLabel, $nPos) EndFunc Edited November 16, 2013 by Rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Seiln Posted November 16, 2013 Author Share Posted November 16, 2013 Thank you for all your replies, it'll take me awhile to read through them and understand it But as soon as I get it and if I have any more questions and clarifications I'll get back to you guys again. 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