Jump to content

Mouse Capture Tool


Recommended Posts

  • Moderators

@PravinJillu welcome to the forum. To answer your question, yes that is all possible in AutoIt, although there are much easier ways to automate Excel than capturing mouseclicks. Please be aware, however, that this forum is dedicated to helping people with their own scripts; it is not a place where people will write it all for you. We are, however, happy to assist you along the way. Take a look at the following:

Quote

...how to make a gui...

See this code as a framework, just to get you started. You can read up on GUI elements in the help file to decide what elements (buttons, input fields, combo boxes, radio buttons, etc.) you want to include in your GUI.

#include <GUIConstantsEx.au3>

    $hGUI = GUICreate("Test", 300, 300)
        GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
Quote

...display mouse cursor X, Y...

Take a look at MouseGetPos in the help file. This function will return the current X,Y coordinates of the mouse. However, as I mentioned, trying to automate Excel through mouseclicks is really unnecessary. Look through the _Excel_ functions in the help file; pretty much anything you want to do within Excel can be done with these functions, in a much more stable manner than mouseclicks.

Do some reading in the help file, try out some of the examples, and see what you can come up with. If you get stuck, please post what you have and we'll do our best to help ;)

"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

2 hours ago, PravinJillu said:

Pravin

Hi Thank you so much!.. Yes i need to learn AUTOIT Let me Try my own scripts and post here:-) 

Quote

Take a look at MouseGetPos in the help file. This function will return the current X,Y coordinates of the mouse. However, as I mentioned, trying to automate Excel through mouseclicks is really unnecessary

Actually i need to record each click as a test step. For example if iam clicking mouse @100,100 then i should write   MouseClick   100,100   In excel  and append the clicks in sequence. Hope you understood.

Thanks for you valuable reply!!

Regards

Pravin

 

Link to comment
Share on other sites

  • Moderators

@PravinJillu then look at _IsPressed in the help file. You can combine this function with the MouseGetPos function, something like this (pseudo-code only, look at the example in the help file):

If _IsPressed(<HexKey For Left Mouse Button>) Then
    ;Write MouseGetPos coordinates to Excel file
EndIf

 

"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

Hi Logan,

Hi i have done some code with Mouse info & excel.. i had struck up with how to concatenate the array element to display 

MouseClick  X,Y

Could you help me in this??

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <Excel.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client ******* Very Important ********
Global $g_idX = 0, $g_idY = 0

; Create application object and create a new workbook
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookNew($oExcel)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
EndIf



;~ MsgBox($MB_SYSTEMMODAL, "Mouse x, y:", $aPos[0] & ", " & $aPos[1])

Example()

Func Example()
    HotKeySet("{ESC}", "GetPos")

    GUICreate("Press Esc to Get Pos", 400, 200)

    GUICtrlCreateLabel("MouseX:", 100, 100, 50)
    GUICtrlCreateLabel("MouseY:", 100, 120, 50)

    $g_idX = GUICtrlCreateLabel("0", 160, 100, 50)
    $g_idY = GUICtrlCreateLabel("0", 160, 120, 50)
    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
    WEnd

    GUIDelete()
EndFunc   ;==>Example

Func GetPos()
;~     Local $a = GUIGetCursorInfo()
    Local $aPos = MouseGetPos()
    GUICtrlSetData($g_idX, $aPos[0] )
    GUICtrlSetData($g_idY, $aPos[1])


; *****************************************************************************
; Write a part of a 2D array to the active sheet in the active workbook
; *****************************************************************************

;~  $$aPos[0][1] = $i & "-" & $j
_ArrayConcatenate ( $aPos,$aPos[0],$aPos[1])

Local $aArray2D[5][5] = [["Sno","Test Step", "Test Action", "Result"], [1, "MouseClick", $aPos]]
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray2D, "A1")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 3", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 3", "2D array successfully written.")

EndFunc   ;==>GetPos

 

 

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...