Mouse And Keyboard Macro Recorder

Post your working scripts, libraries and tools for AHK v1.1 and older
gustavo
Posts: 3
Joined: 08 Apr 2021, 08:52

Re: Mouse And Keyboard Macro Recorder

Post by gustavo » 15 Jan 2022, 09:23

Impressive! Awesome

Simple and efficient

Thanks a lot bro

Greetings from Brazil

Hamed_Sabagh
Posts: 1
Joined: 15 Apr 2022, 00:20
Contact:

Re: Mouse And Keyboard Macro Recorder

Post by Hamed_Sabagh » 15 Apr 2022, 00:24

Thank you so much. I was searching for a code like that for ages. You are a life saver!! 谢谢我的好同伴.

FrankNFurter
Posts: 5
Joined: 17 Oct 2020, 02:22

Re: Mouse And Keyboard Macro Recorder

Post by FrankNFurter » 23 Apr 2022, 20:02

Script doesn't seem to have the timings down right. I was using it to record a situation that was fairly precise, did the recording and it shaved off a good 2 seconds making it not do as it needed to. Any ideas?

feiyue
Posts: 349
Joined: 08 Aug 2014, 04:08

Re: Mouse And Keyboard Macro Recorder

Post by feiyue » 24 Apr 2022, 19:56

@FrankNFurter
LogArr.Push("Sleep, " (Delay//2)) ; To speed up playback, I actually cut the delay by half. :D

ihightower
Posts: 3
Joined: 08 May 2022, 07:13

Re: Mouse And Keyboard Macro Recorder

Post by ihightower » 08 May 2022, 07:20

I don't understand.. the first posting shows Macro Recorder v2.1 By FeiYue
but as i read more posts in the next pages.. it has v4.6 Mouse And Keyboard Macro Recorder v4.6
then it is sent in as zip file by other poster, and he says latest is v2.1 and also attaches the files of v4.6

my question is what is really the latest script? and why the original author feiyue has not updated the first posting to v4.6.
should i use v2.1 or v4.6. Each time when feiyue updates the script, why the new version is not in the posting?
@feiyue Thank you.

gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: Mouse And Keyboard Macro Recorder

Post by gregster » 08 May 2022, 08:39

feiyue wrote:
26 May 2018, 10:09
I've updated it to v4.0 to write more complex scripts, but it's more complex for use, and some private preferences are not suitable for everyone.
So I restored the previous version, only to achieve simple functions, to facilitate the use of novice.
feiyue wrote:
30 May 2019, 01:34
My original intention was to provide a simple recording tool for beginners.
As I added more and more private functions to this recording tool,
it became more and more complex, making it difficult for beginners to use.
My English is not good enough to explain how to use it clearly.
So I gave up the later version.
Nevertheless, later versions were provided by another user (burque505) who still had them, because some people were asking. But the latest version supported by feiyue seems to be version 2.1 from March 2020, which you can find in the first post of this topic.

ihightower
Posts: 3
Joined: 08 May 2022, 07:13

Re: Mouse And Keyboard Macro Recorder

Post by ihightower » 08 May 2022, 10:24

gregster wrote:
08 May 2022, 08:39
feiyue wrote:
26 May 2018, 10:09
I've updated it to v4.0 to write more complex scripts, but it's more complex for use, and some private preferences are not suitable for everyone.
So I restored the previous version, only to achieve simple functions, to facilitate the use of novice.
feiyue wrote:
30 May 2019, 01:34
My original intention was to provide a simple recording tool for beginners.
As I added more and more private functions to this recording tool,
it became more and more complex, making it difficult for beginners to use.
My English is not good enough to explain how to use it clearly.
So I gave up the later version.
Nevertheless, later versions were provided by another user (burque505) who still had them, because some people were asking. But the latest version supported by feiyue seems to be version 2.1 from March 2020, which you can find in the first post of this topic.
Thank you so much for the clarification. It makes sense now, that things are put together with your above explanation.

tenace
Posts: 1
Joined: 24 Jun 2022, 15:47

Re: Mouse And Keyboard Macro Recorder

Post by tenace » 24 Jun 2022, 15:49

Great script! Dow you know:

1) How to make it loop?
2) How to make it loop in the background?
3) How to eliminite the menu while running it?

Regards,

Tenace

robw92
Posts: 1
Joined: 18 Sep 2022, 05:59

Re: Mouse And Keyboard Macro Recorder

Post by robw92 » 18 Sep 2022, 06:06

After recording the macro, how do I add it to a new script to get it to run?

Vladimir
Posts: 16
Joined: 27 Nov 2019, 23:12

Re: Mouse And Keyboard Macro Recorder

Post by Vladimir » 05 Oct 2022, 23:57

I would like to record a macro or to write a script that would contain a combination for a Windows screen contrast setting that can be found in
Control Panel > Accessibility/Ease of Access

Left Alt + Left Shift + Print Screen.

The Macro recorder script cannot change system combinations like this.
What should I do to capture and to recreate them?

Thank you.

yasin7070
Posts: 17
Joined: 10 Feb 2022, 12:06

Re: Mouse And Keyboard Macro Recorder

Post by yasin7070 » 11 Nov 2022, 03:41

@feiyue
Excellent Work ❤

adrian_9832
Posts: 26
Joined: 23 Dec 2018, 00:40

Re: Mouse And Keyboard Macro Recorder

Post by adrian_9832 » 17 Dec 2022, 08:40

good job and thank you !!

zrlaa
Posts: 1
Joined: 06 Mar 2023, 22:55

Re: Mouse And Keyboard Macro Recorder

Post by zrlaa » 06 Mar 2023, 22:58

is there a way for it to record sleep times between keys being pressed?
image.png
image.png (1.93 KiB) Viewed 5424 times

Raghava Doregowda
Posts: 130
Joined: 06 Nov 2022, 01:48

Re: Mouse And Keyboard Macro Recorder

Post by Raghava Doregowda » 11 Mar 2023, 01:57

feiyue wrote:
08 Jul 2017, 08:30
This is a useful script to record mouse, keyboard actions and playback.
Using it, You can quickly write simple automated scripts.
Hope you like it. :dance:

Code: Select all

;-----------------------------------
;  Macro Recorder v2.1  By FeiYue
;
;  Description: This script records the mouse
;  and keyboard actions and then plays back.
;
;  F1  -->  Record(Screen) (CoordMode, Mouse, Screen)
;  F2  -->  Record(Window) (CoordMode, Mouse, Window)
;  F3  -->  Stop   Record/Play
;  F4  -->  Play   LogFile
;  F5  -->  Edit   LogFile
;  F6  -->  Pause  Record/Play
;
;  Note:
;  1. press the Ctrl button individually
;     to record the movement of the mouse.
;  2. Shake the mouse on the Pause button,
;     you can pause recording or playback.
;-----------------------------------

#NoEnv
SetBatchLines, -1
Thread, NoTimers
CoordMode, ToolTip
SetTitleMatchMode, 2
DetectHiddenWindows, On
;--------------------------
LogFile:=A_Temp . "\~Record.txt"
UsedKeys:="F1,F2,F3,F4,F5,F6"
Play_Title:=RegExReplace(LogFile,".*\\") " ahk_class AutoHotkey"
;--------------------------
Gui, +AlwaysOnTop -Caption +ToolWindow +E0x08000000 +Hwndgui_id
Gui, Margin, 0, 0
Gui, Font, s12
s:="[F1]Record(Screen),[F2]Record(Window),"
  . "[F3]Stop,[F4]Play,[F5]Edit,[F6] Pause "
For i,v in StrSplit(s, ",")
{
  j:=i=1 ? "":"x+0", j.=InStr(v,"Pause") ? " vPause":""
  Gui, Add, Button, %j% gRun, %v%
}
Gui, Add, Button, x+0 w0 Hidden vMyText
Gui, Show, NA y0, Macro Recorder
OnMessage(0x200,"WM_MOUSEMOVE")
;--------------------------
SetTimer, OnTop, 2000
OnTop:
Gui, +AlwaysOnTop
return

Run:
if IsLabel(k:=RegExReplace(RegExReplace(A_GuiControl,".*]"),"\W"))
  Goto, %k%
return

WM_MOUSEMOVE() {
  static OK_Time
  ListLines, Off
  if (A_Gui=1) and (A_GuiControl="Pause")
    and (t:=A_TickCount)>OK_Time
  {
    OK_Time:=t+500
    Gosub, Pause
  }
}

ShowTip(s:="", pos:="y35", color:="Red|00FFFF") {
  static bak, idx
  if (bak=color "," pos "," s)
    return
  bak:=color "," pos "," s
  SetTimer, ShowTip_ChangeColor, Off
  Gui, ShowTip: Destroy
  if (s="")
    return
  ; WS_EX_NOACTIVATE:=0x08000000, WS_EX_TRANSPARENT:=0x20
  Gui, ShowTip: +LastFound +AlwaysOnTop +ToolWindow -Caption +E0x08000020
  Gui, ShowTip: Color, FFFFF0
  WinSet, TransColor, FFFFF0 150
  Gui, ShowTip: Margin, 10, 5
  Gui, ShowTip: Font, Q3 s20 bold
  Gui, ShowTip: Add, Text,, %s%
  Gui, ShowTip: Show, NA %pos%, ShowTip
  SetTimer, ShowTip_ChangeColor, 1000
  ShowTip_ChangeColor:
  Gui, ShowTip: +AlwaysOnTop
  r:=StrSplit(SubStr(bak,1,InStr(bak,",")-1),"|")
  Gui, ShowTip: Font, % "Q3 c" r[idx:=Mod(Round(idx),r.length())+1]
  GuiControl, ShowTip: Font, Static1
  return
}


;============ Hotkey =============


F1::
Suspend, Permit
Goto, RecordScreen

F2::
Suspend, Permit
Goto, RecordWindow

RecordScreen:
RecordWindow:
if (Recording or Playing)
  return
Coord:=InStr(A_ThisLabel,"Win") ? "Window":"Screen"
LogArr:=[], oldid:="", Log(), Recording:=1, SetHotkey(1)
ShowTip("Recording")
return


F3::
Stop:
Suspend, Permit
if Recording
{
  if (LogArr.MaxIndex()>0)
  {
    s:="`nLoop, 1`n{`n`nSetTitleMatchMode, 2"
      . "`nCoordMode, Mouse, " Coord "`n"
    For k,v in LogArr
      s.="`n" v "`n"
    s.="`nSleep, 1000`n`n}`n"
    s:=RegExReplace(s,"\R","`n")
    FileDelete, %LogFile%
    FileAppend, %s%, %LogFile%
    s:=""
  }
  SetHotkey(0), Recording:=0, LogArr:=""
}
else if Playing
{
  WinGet, list, List, %Play_Title%
  Loop, % list
    if WinExist("ahk_id " list%A_Index%)!=A_ScriptHwnd
    {
      WinGet, pid, PID
      WinClose,,, 3
      IfWinExist
        Process, Close, %pid%
    }
  SetTimer, CheckPlay, Off
  Playing:=0
}
ShowTip()
Suspend, Off
Pause, Off
GuiControl,, Pause, % "[F6] Pause "
isPaused:=0
return


F4::
Play:
Suspend, Permit
if (Recording or Playing)
  Gosub, Stop
ahk:=A_IsCompiled ? A_ScriptDir "\AutoHotkey.exe" : A_AhkPath
IfNotExist, %ahk%
{
  MsgBox, 4096, Error, Can't Find %ahk% !
  Exit
}
Run, %ahk% /r "%LogFile%"
SetTimer, CheckPlay, 500
Gosub, CheckPlay
return

CheckPlay:
Check_OK:=0
WinGet, list, List, %Play_Title%
Loop, % list
  if (list%A_Index%!=A_ScriptHwnd)
    Check_OK:=1
if Check_OK
  Playing:=1, ShowTip("Playing")
else if Playing
{
  SetTimer, CheckPlay, Off
  Playing:=0, ShowTip()
}
return


F5::
Edit:
Suspend, Permit
Gosub, Stop
Run, notepad.exe "%LogFile%"
return


F6::
Pause:
Suspend, Permit
if Recording
{
  Suspend
  Pause, % A_IsSuspended ? "On":"Off", 1
  isPaused:=A_IsSuspended, Log()
}
else if Playing
{
  isPaused:=!isPaused
  WinGet, list, List, %Play_Title%
  Loop, %list%
    if WinExist("ahk_id " list%A_Index%)!=A_ScriptHwnd
      PostMessage, 0x111, 65306
}
else return
if isPaused
  GuiControl,, Pause, [F6]<Pause>
else
  GuiControl,, Pause, % "[F6] Pause "
return


;============ Functions =============


SetHotkey(f:=0) {
  ; These keys are already used as hotkeys
  global UsedKeys
  f:=f ? "On":"Off"
  Loop, 254
  {
    k:=GetKeyName(vk:=Format("vk{:X}", A_Index))
    if k not in ,Control,Alt,Shift,%UsedKeys%
      Hotkey, ~*%vk%, LogKey, %f% UseErrorLevel
  }
  For i,k in StrSplit("NumpadEnter|Home|End|PgUp"
    . "|PgDn|Left|Right|Up|Down|Delete|Insert", "|")
  {
    sc:=Format("sc{:03X}", GetKeySC(k))
    if k not in ,Control,Alt,Shift,%UsedKeys%
      Hotkey, ~*%sc%, LogKey, %f% UseErrorLevel
  }
  SetTimer, LogWindow, %f%
  if (f="On")
    Gosub, LogWindow
}

LogKey:
LogKey()
return

LogWindow:
LogWindow()
return

LogKey() {
  Critical
  k:=GetKeyName(vksc:=SubStr(A_ThisHotkey,3))
  k:=StrReplace(k,"Control","Ctrl"), r:=SubStr(k,2)
  if r in Alt,Ctrl,Shift,Win
    LogKey_Control(k)
  else if k in LButton,RButton,MButton
    LogKey_Mouse(k)
  else
  {
    if (k="NumpadLeft" or k="NumpadRight") and !GetKeyState(k,"P")
      return
    k:=StrLen(k)>1 ? "{" k "}" : k~="\w" ? k : "{" vksc "}"
    Log(k,1)
  }
}

LogKey_Control(key) {
  global LogArr, Coord
  k:=InStr(key,"Win") ? key : SubStr(key,2)
  if (k="Ctrl")
  {
    CoordMode, Mouse, %Coord%
    MouseGetPos, X, Y
  }
  Log("{" k " Down}",1)
  Critical, Off
  KeyWait, %key%
  Critical
  Log("{" k " Up}",1)
  if (k="Ctrl")
  {
    i:=LogArr.MaxIndex(), r:=LogArr[i]
    if InStr(r,"{Blind}{Ctrl Down}{Ctrl Up}")
      LogArr[i]:="MouseMove, " X ", " Y
  }
}

LogKey_Mouse(key) {
  global gui_id, LogArr, Coord
  k:=SubStr(key,1,1)
  CoordMode, Mouse, %Coord%
  MouseGetPos, X, Y, id
  if (id=gui_id)
    return
  Log("MouseClick, " k ", " X ", " Y ",,, D")
  CoordMode, Mouse, Screen
  MouseGetPos, X1, Y1
  t1:=A_TickCount
  Critical, Off
  KeyWait, %key%
  Critical
  t2:=A_TickCount
  if (t2-t1<=200)
    X2:=X1, Y2:=Y1
  else
    MouseGetPos, X2, Y2
  i:=LogArr.MaxIndex(), r:=LogArr[i]
  if InStr(r, ",,, D") and Abs(X2-X1)+Abs(Y2-Y1)<5
    LogArr[i]:=SubStr(r,1,-5), Log()
  else
    Log("MouseClick, " k ", " (X+X2-X1) ", " (Y+Y2-Y1) ",,, U")
}

LogWindow() {
  global oldid, LogArr
  static oldtitle
  id:=WinExist("A")
  WinGetTitle, title
  WinGetClass, class
  if (title="" and class="")
    return
  if (id=oldid and title=oldtitle)
    return
  oldid:=id, oldtitle:=title
  title:=SubStr(title,1,50)
  if (!A_IsUnicode)
  {
    GuiControl,, MyText, %title%
    GuiControlGet, s,, MyText
    if (s!=title)
      title:=SubStr(title,1,-1)
  }
  title.=class ? " ahk_class " class : ""
  title:=RegExReplace(Trim(title), "[``%;]", "``$0")
  s:="tt = " title "`nWinWait, %tt%"
    . "`nIfWinNotActive, %tt%,, WinActivate, %tt%"
  i:=LogArr.MaxIndex(), r:=LogArr[i]
  if InStr(r,"tt = ")=1
    LogArr[i]:=s, Log()
  else
    Log(s)
}

Log(str:="", Keyboard:=0) {
  global LogArr
  static LastTime
  t:=A_TickCount, Delay:=(LastTime ? t-LastTime:0), LastTime:=t
  IfEqual, str,, return
  i:=LogArr.MaxIndex(), r:=LogArr[i]
  if (Keyboard and InStr(r,"Send,") and Delay<1000)
  {
    LogArr[i]:=r . str
    return
  }
  if (Delay>200)
    LogArr.Push("Sleep, " (Delay//2))
  LogArr.Push(Keyboard ? "Send, {Blind}" str : str)
}

;============ The End ============

;
I think this might be the exact one that most of us are looking for. Some small querks and this could be a gamechanger.
1) Anyway to disable mouse interaction entirely? (Oh, btw control key sometimes is not cutting out the mouse. I didn't exactly understand "when" to press control. Before or during the recording?)
2) Any way to make the keystrokes play quickly? Like not wait based on human speed? Atleast an option to between playback in lightning speed or human speed as recorded?

User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Mouse And Keyboard Macro Recorder

Post by SpeedMaster » 19 Mar 2023, 12:31

Raghava Doregowda wrote:
11 Mar 2023, 01:57
1) Anyway to disable mouse interaction entirely?
2) Any way to make the keystrokes play quickly?
tenace wrote:
24 Jun 2022, 15:49
3) How to eliminite the menu while running it?
@Raghava Doregowda , @tenace
You may try this slightly modified version (v2.1+) :geek:
:arrow: viewtopic.php?f=6&t=34184&p=158990#p158990

Regards

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Mouse And Keyboard Macro Recorder

Post by Krd » 20 Mar 2023, 04:08

Anyone please update this to work with AHKv2? :)

DarkSnoops
Posts: 1
Joined: 03 Apr 2023, 21:47

Re: Mouse And Keyboard Macro Recorder

Post by DarkSnoops » 03 Apr 2023, 21:51

Hi !
Has anyone converted his script to AHK V 2.0 ? :D

kostiantyndvornik
Posts: 3
Joined: 25 Jun 2023, 05:01

Re: Mouse And Keyboard Macro Recorder

Post by kostiantyndvornik » 25 Jun 2023, 05:04

Hello. Working of such tool for record and playback input based on original post. Planning to submit to GitHub soon the code
https://www.youtube.com/watch?v=RrRIE1z0XGw


ahkHereToLearn
Posts: 5
Joined: 19 Aug 2023, 14:28

Re: Mouse And Keyboard Macro Recorder

Post by ahkHereToLearn » 29 Aug 2023, 20:19

I've been using FeiYue's macro recorder script for months. I have a Win 11 Virtual Machine. On that virtual machine, I am running the script. I often connect to a Windows 365 cloud PC via that virtual machine. Previously, I would need to have the win365 cloud PC just-slight minimized so that it wasn't 100% full screen. I would see Feiyue's GUI on top, and I could record clicks and keystrokes, etc within / on top of the 365 cloud pc. Today, out of the blue, I am no longer able to record clicks or keystrokes. I hit the record button, I click around inside the Cloud PC, or I type some text for input, and then I click to stop recording. Then when I hit 'edit,' in his GUI, instead of seeing whatever should have been recorded, I just have this instead:

Code: Select all

Loop, 1
{

SetTitleMatchMode, 2
CoordMode, Mouse, Screen

tt = Cloud PC Enterprise 2vCPU/4GB/128GB ahk_class TscShellContainerClass
WinWait, %tt%
IfWinNotActive, %tt%,, WinActivate, %tt%

Sleep, 1000

}


with none of the interactions having been recorded. Interestingly, the same behavior used to occur if I tried recording with the Cloud PC in fullscreen (within the VM), but as long as I shrunk the window just a bit, the recording would be fine. Can anyone suggest what might have changed? I know it wasn't FeiYue's macro recorder. I know it's not my own behavior. Could 'they' have added some new invisible 'layer' that is preventing my interactions from being recorded? Thanks for any advice.

Post Reply

Return to “Scripts and Functions (v1)”