The AutoHotkey script sharing thread

For those unfamiliar, AutoHotkey is a Windows utility that allows you to define custom keyboard shortcuts that do all sort of things, and is an incredible tool for simple automation and slightly speeding up your work in any program.
This is especially useful in RPG Maker - if you're going to spend multiple years on a project, spending a day or two on making your workflow faster is bound to pay off multiple times over.

And what's even better than making your own AutoHotkey scripts? Using scripts other people have already made 😛
If you've made any, for any RM version, feel free to share them here.

And with that, here are mine (for MV). I'll describe what they do, but I'll assume you are familiar with the very basics - though if you have any questions about them, no matter how simple, feel free to ask them!
Spoiler: Show Text window
The main window for writing dialogue, which I like to do without taking my hands off the keyboard, so I've made a bunch of hotkeys to enable that. All of them assume that you have the text input field currently active.

First of all, there's of course this line, to limit the scope to just this window
#IfWinActive Show Text

Toggle batch input mode with Alt+B:
!b:: Send {Tab 4}{Space}+{Tab 4}

Press Alt to change current face graphic (within the same file), and then enter to select it:
Code:
LAlt::
Send {Tab 7}{Space}
Sleep 200
Send {Tab}
KeyWait, Enter, D
Send {Tab}
return
(this would normally end with the face button selected instead of the text field - this is why we wait for enter to be pressed, and then send Tab)

Use Crtl+T to change face to the main character's
JavaScript:
^t Up::
Send {Tab 7}{Space}
Sleep 250
Send m{Enter}
Sleep 100
Send {Tab}
return
Key part here is Send m - this will select the first file with a name that starts with "m" - you might want to use a different letter, and add some {Down} commands if it's not the first one.
And you can of course make more of these, one for each face file you use often.

Run a quick event test of the current message with Ctrl+R (it's like preview, but it actually works 😛 )
Code:
^r::
Send {Tab 4}^{Enter}
if WinExist("ahk_exe Game.exe") {   
    WinClose
}
;Repeat it if the first one only closed the console
if WinExist("ahk_exe Game.exe") {
    WinClose
}
Sleep 50
Send ^r
WinWaitActive, Mysteries of the Vault
Sleep 1000
WinWaitActive, ahk_exe RPGMV.exe
Sleep 10
Send {Space}
return
Just replace "Mysteries of the Vault" with the title of your game's window 😉
It works best if you have event tests set to close the window when they're done, but I guess closing them with Alt+F4 or going back with Alt+Tab would also be valid options.

Italisize text with Ctrl+I (assuming you have Message Core that adds italic text with \fi):
Code:
^i::
OldClipboard := Clipboard
Send ^c
Send \fi
Send ^v
Send \fi
If (StrLen(%Clipboard%) == 0)
    Send {Left 3}
Sleep 100
Clipboard := OldClipboard
return
This is context dependant: if you select some text and press Ctrl+I it will wrap that text with \fi tags. Otherwise, it will just insert \fi\fi and put your cursor in the middle.

Type "\..\..\.." faster:
:?*:\..::\..\..\..
I use "\..\..\.." to signify a pause when a character is thinking (and I'm making a puzzle game - this happens a lot!), so I've set up a simple hotstring that types it when I type just "\..".

Spoiler: Main editor
First of all, of course there's the scope limiter:
#IfWinActive ahk_exe RPGMV.exe ;RPG Maker MV

Send Crtl+Enter by pressing right shift:
RShift:: Send ^{Enter}
The simplest, but by far my most used hotkey. In case you didn't know, Crtl+Enter is the equivalent of pressing the OK button in any window. When I finish typing a message (with Enter used for new lines as normal), I just press right shift to exit it.

Go to the test map with Alt+T:
JavaScript:
!t::
MouseGetPos, mouseX, mouseY
MouseClick, L, 97, 1003
MouseMove, %mouseX%, %mouseY%
return
Of course the coords for MouseClick will depend on your resolution and where your test map is. Yes, I do go there often enough to warrant a shortcut 😛 . You can also set these for other commonly used maps of course.

Event test fix:
Code:
^+r::
Send ^a
^r::
if WinExist("ahk_exe Game.exe") {   
    WinClose
}
;Repeat it if the first one only closed the console
if WinExist("ahk_exe Game.exe") {
    WinClose
}
Send ^r
return
Normally, when you enter an event test (by selecting some event commands and pressing Ctrl+R), it won't do anything if the game's window already exists. This hotkey will close it for you before starting one. As a bonus, Ctrl+Shift+R will select all command on the current page first.

Increase scroll wheel's speed 4 times:
Code:
Wheelup:: Send {Wheelup 4}
Wheeldown:: Send {Wheeldown 4}
The default just felt way too slow for me. You can also do the same for WheelLeft and WheelRight if your mouse has that.

Switch between event tabs (or tabs when selecting a command) with Ctrl+Tab and Ctrl+Shift+Tab:
Code:
^Tab::
MouseGetPos, mouseX, mouseY
PixelSearch, Px, Py, 19, 98, 800, 115, 0x464B4C, 0, Fast RGB
if ErrorLevel {
    PixelSearch, Px, Py, 12, 37, 122, 60, 0x464B4C, 0, Fast RGB
    if ErrorLevel {
        MsgBox, "Failed to find the active tab."
        return
    }
}
Pxx := Px + 50
MouseClick, L, %Pxx%, %Py%
MouseMove, %mouseX%, %mouseY%
return

+^Tab::
MouseGetPos, mouseX, mouseY
PixelSearch, Px, Py, 19, 98, 800, 115, 0x464B4C, 0, Fast RGB
if ErrorLevel {
    PixelSearch, Px, Py, 12, 37, 122, 60, 0x464B4C, 0, Fast RGB
    if ErrorLevel {
        MsgBox, "Failed to find the active tab."
        return
    }
}
Pxx := Px - 25
MouseClick, L, %Pxx%, %Py%
MouseMove, %mouseX%, %mouseY%
return
This one was a bit tricky to do, since there's no way to activate those reliably with the keyboard. This macro will look for a specific colour within the window to find the currently active tab, and click with some offset from it.

Playtesting with F11:
Code:
^F11::
MouseGetPos, mouseX, mouseY
MouseClick, R
Sleep 100
Send {Down 10}{Right}
MouseMove, 275, 265, 1, R
Sleep 50
MouseClick, L
MouseClick, L
Sleep 50
MouseMove, %mouseX%, %mouseY%
;Proceeding to regular F11 - do not reorder those

F11::
Loop, 5 {
    Send ^{Enter}
    Sleep 10
}
Sleep 10
Send ^s
Sleep 10
chromePageWait()
if WinExist("ahk_exe Game.exe") {       
    WinActivate   
    Sleep 20
    Send {F5}
} else {
    Send ^r
}
return

;By Sergio https://autohotkey.com/board/topic/65742-have-script-wait-while-page-loads-in-google-chrome/
chromePageWait()        
{                       
global                  
Loop 10                 
    {                   
    while (A_Cursor = "AppStarting")
        continue        
    Sleep, 5
    }                   
}
This one does a few things: saves the game, waits until it's saved, then switches to your game's window if it exists and reloads it, otherwise just sends Ctrl+R. If you press Ctrl+F11, it will also set the player's starting position where your mouse is.

Paste text into a string with Ctrl+P:
Code:
^p Up::
OldClipboard := Clipboard
Clipboard := StrReplace(Clipboard, "`r", "")
Clipboard := StrReplace(Clipboard, "\", "\\")
Clipboard := StrReplace(Clipboard, """", "\""") ;Replaces " with \"
Clipboard := StrReplace(Clipboard, "`n", "\n")
Clipboard = `"%Clipboard%\n`"
Sleep 10
Send {Space}
Sleep 150
Send +{Tab 3}
Send ^a{Delete}
Sleep 10
Send ^v
Sleep 50
Send {Enter}
Clipboard := OldClipboard
return
That's the last one, and probably the one most specific to my project that's still worth sharing. When I want to show a large amount of text to the player, I put that text into a variable and run a script. This hotkey will do the first part, while also making sure the text will work fine inside a string - it converts newlines to '\n', replaces "with \" etc.

I do have some more project-specific ones, but I think that's about it when it comes to things other people might also find useful 😛

Please feel free to also use this thread to share any macro ideas you have but don't know how to implement or just talk about AutoHotkey in general 😉

Original thread: https://forums.rpgmakerweb.com/threads/the-autohotkey-script-sharing-thread.165577/