Jump to content

Recommended Posts

Posted (edited)

I am totally not happy with the recorder program thing and how it only works with the wrong coord mode for the mouse etc. So... I am making my own "script automation maker" type deal.. Anyone else done this for themselves / others ?So far I have it working enough to where I have my hotkeys for what actions I want to do and I can draw a picture in paint and have it replicate it any time on different resolutions because I can selectively choose my coord mode and really make a custom automated script.

So far I have hotkeys for:

Toggle mouse coord mode

Left click

Left mouse down

Left mouse up

Start/Stop record (track) mouse movements in real time

Input text

Input key combo's

Wait for this current active window to be active

Exit program.

These all let me choose what to do. It is mostly working but its still alpha stage yet. I want to enhance it by making the mouse button togglable like I did for the coord mode so I can select left or right click etc. Also I am going to make some changes that each time I toggle the coord mode it wont write to the file until after like a couple seconds to avoid waste code.

What do you think to my project? (edit: Code is in the next message)

Edited by Morthawt
Posted (edited)

Here is the code in case you want to "see" what I am working on rather than just have the description. It is not *finished* so... but it does "work"

Opt('MouseCoordMode', 2)
Global $currentcoordmode = 2
Global $coordmode[3][2]
Global $splashtextkeys
Global $splashtext
Global $splashtextcoordmode
$coordmode[0][1] = 'Relative to the active window'
$coordmode[1][1] = 'Absolute screen coordinates'
$coordmode[2][1] = 'Relative to client area of active window'
 
Global $coordmodelable = $coordmode[$currentcoordmode][1]
 
Global $end = 0
Global $last0
Global $last1
$file = 'automationcreator.au3'
FileDelete($file)
FileWrite($file, "Opt('MouseCoordMode', 2)" & @CRLF & "Sleep(2000)" & @CRLF)
FileWrite($file, "HotKeySet('^!#0', 'ExitProgram')" & @CRLF & _
    "Func ExitProgram()" & @CRLF & _
    "Exit" & @CRLF & _
    "EndFunc" & @CRLF)
;*Single click
;*Mouse down
;*Mouse up
;*Mouse Move to
;*Mouse track movement
;*Toggle coordinate mode
;*Push key combo
;*Input text
;Write comment to script
;Run program
 
SplashKey()
Func SplashKey()
 
$splashtextcoordmode = 'Mouse coordinate measure mode:' & @LF & '[ ' & $coordmodelable & ' ]' & @LF & @LF
$splashtextkeys = _
   'Ctrl Win Alt 1 = Toggle mouse coordinate mode' & @LF & _
   'Ctrl Win Alt 2 = Left click mouse' & @LF & _
   'Ctrl Win Alt 3 = Left mouse button hold down' & @LF & _
   'Ctrl Win Alt 4 = Left mouse button release' & @LF & _
   'Ctrl Win Alt 5 = Start/Stop record mouse movements' & @LF & _
   'Ctrl Win Alt 6 = Input text' & @LF & _
   'Ctrl Win Alt 7 = Input key combo''s' & @LF & _
   'Ctrl Win Alt 8 = Wait for this current active window to be active' & @LF & _
   @LF & 'Ctrl Win Alt 0 = Exit program'
SplashTextOn("Key Control Combo's", $splashtextcoordmode & $splashtextkeys, 330, 200, 20, 20, 20, '', 8)
 
EndFunc   ;==>SplashKey
 
BindHotKeys()
While 1
Sleep(1000)
WEnd
 
Func BindHotKeys()
HotKeySet('^!#1', 'CoordMode')
HotKeySet('^!#2', 'LClickMouse')
HotKeySet('^!#3', 'LMouseDown')
HotKeySet('^!#4', 'LMouseUp')
HotKeySet('^!#5', 'MouseTrackMovement')
HotKeySet('^!#6', 'InputTextData')
HotKeySet('^!#7', 'InputKeyPress')
HotKeySet('^!#8', 'WaitForThisWindow')
HotKeySet('^!#0', 'ExitProgram')
EndFunc   ;==>BindHotKeys
Func UnBindHotKeys()
HotKeySet('^!#1')
HotKeySet('^!#2')
HotKeySet('^!#3')
HotKeySet('^!#4')
HotKeySet('^!#5')
HotKeySet('^!#6')
HotKeySet('^!#7')
HotKeySet('^!#8')
HotKeySet('^!#0')
EndFunc   ;==>UnBindHotKeys
Func WaitForThisWindow()
$window = WinGetTitle("[ACTIVE]", "")
$window = StringReplace($window, '"', '""')
FileWrite($file, 'WinWaitActive("' & $window & '")' & @CRLF )
 
EndFunc   ;==>WaitForThisWindow
 
 
Func ExitProgram()
Exit
EndFunc   ;==>ExitProgram
 
Func InputTextData()
$input = InputBox('Text Input', 'Input your text here')
$input = StringReplace($input, "'", "''")
$inputlength = StringLen($input)
FileWrite($file, 'Send(''' & $input & ''', 1)' & @CRLF)
Send($input, 1)
EndFunc   ;==>InputTextData
Func InputKeyPress()
$input = InputBox('Text Input', 'Input your key combo''s here' & @CRLF & 'Shortcut Modifier Keys:' & @CRLF & @CRLF & _
   'ALT = ! CTRL = ^ SHIFT = + WIN = #' & @CRLF & @CRLF & _
   'Special keys are marked like:' & @CRLF & @CRLF & _
   'TAB = {TAB} A = A B = B F1 = {F1}' & @CRLF & @CRLF & _
   'Example ALT F = +f WIN TAB = #{TAB}' & @CRLF & @CRLF & _
   'To send the {DOWN} arrow key 5 times type:' & @CRLF & _
   '{DOWN 5}', '', '', 300, 300)
 
$input = StringReplace($input, "'", "''")
 
$inputlength = StringLen($input)
FileWrite($file, 'Send(''' & $input & ''')' & @CRLF)
Send($input)
EndFunc   ;==>InputKeyPress
 
Func LClickMouse()
$position = MouseGetPos()
FileWrite($file, "MouseMove(" & $position[0] & ", " & $position[1] & ", 0)" & @CRLF)
FileWrite($file, "Sleep(100)" & @CRLF)
FileWrite($file, "MouseClick('left')" & @CRLF)
MouseClick('left')
EndFunc   ;==>LClickMouse
 
Func LMouseDown()
$position = MouseGetPos()
FileWrite($file, "MouseMove(" & $position[0] & ", " & $position[1] & ", 0)" & @CRLF)
FileWrite($file, "Sleep(100)" & @CRLF)
FileWrite($file, "MouseDown('left')" & @CRLF)
MouseDown('left')
EndFunc   ;==>LMouseDown
 
 
Func LMouseUp()
$position = MouseGetPos()
FileWrite($file, "MouseMove(" & $position[0] & ", " & $position[1] & ", 0)" & @CRLF)
FileWrite($file, "Sleep(100)" & @CRLF)
FileWrite($file, "MouseUp('left')" & @CRLF)
MouseUp('left')
EndFunc   ;==>LMouseUp
 
Func EndOperation()
$end = 1
EndFunc   ;==>EndOperation
 
Func CoordMode()
If $currentcoordmode > 1 Then
  $currentcoordmode = 0
Else
  $currentcoordmode += 1
EndIf
Opt('MouseCoordMode', $currentcoordmode)
$coordmodelable = $coordmode[$currentcoordmode][1]
FileWrite($file, "Opt('MouseCoordMode', " & $currentcoordmode & ")" & @CRLF)
$splashtextcoordmode = 'Mouse coordinate measure mode:' & @LF & '[ ' & $coordmodelable & ' ]' & @LF & @LF
 
ControlSetText("Key Control Combo's", "", "Static1", $splashtextcoordmode & $splashtextkeys, 1)
 
EndFunc   ;==>CoordMode
 
Func MouseTrackMovement()
HotKeySet('^!#5', 'EndOperation')
$position = MouseGetPos()
FileWrite($file, 'MouseMove(' & $position[0] & ',' & $position[1] & ',1)' & @CRLF)
FileWrite($file, "Sleep(100)" & @CRLF)
While 1
  $position = MouseGetPos()
 
  If $position[0] <> $last0 Or $position[1] <> $last1 Then
   $last0 = $position[0]
   $last1 = $position[1]
   FileWrite($file, 'MouseMove(' & $position[0] & ',' & $position[1] & ',0)' & @CRLF)
   FileWrite($file, "Sleep(2)" & @CRLF)
  EndIf
  If $end = 1 Then
   $end = 0
   HotKeySet('^!#5', 'MouseTrackMovement')
   ExitLoop
  EndIf
  Sleep(1)
WEnd
EndFunc   ;==>MouseTrackMovement
Edited by Morthawt
Posted

Hi - nice work on this script.

I'm a relative newbie to this [AutoIt], but I don't like the mouse position recording (relative or absolute).

Is there some way to interrogate the underlying page html and determine the id of the element/object being clicked and return/record that instead of the position?

Thanks

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
  • Recently Browsing   0 members

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