Fangames > Gameplay & Discussion

Guide: Using Autohotkey to change controls, window size and volume

(1/2) > >>

Syd:
Hi Guys  :atkHappy:

There are three things that bother me about fangames. The controls, the small window size, and the high volume. Most of the veteran players probably learned to live with this, but for the rest of you, I made this little guide on how to deal with those issues using Autohotkey.

To create a new Autohotkey script, simply create a .txt file and change the file extension to .ahk after you are done edititing it.

First, add this line to the top of your script:

--- Code: ---#IfWinActive ahk_class TRunnerForm
--- End code ---
With this line the script will only work when a fangame-window (or any other gamemaker-exe) is active. That way you can keep the script running in the background while you are doing stuff other than playing fangames. If let it autorun with windows, and it has never caused any problems at all.
For Gamemaker-Studio games this line needs to be different: #IfWinActive ahk_class YYGameMakerYY. For MMF games (Boshy and the orginal IWBTG) it should be #IfWinActive ahk_class Mf2MainClassTh.

Edit: If just found out you can create custom window-groups. So you can group GameMaker 8, Studio and MMF games together:

--- Code: ---GroupAdd, Fangame, ahk_class TRunnerForm
GroupAdd, Fangame, ahk_class YYGameMakerYY
GroupAdd, Fangame, ahk_class Mf2MainClassTh

#IfWinActive ahk_group Fangame

--- End code ---

Also, add this line to the beginning of the script, otherwise you might get a message saying that you activated to many hotkeys in the last few seconds:
#MaxHotkeysPerInterval 9999

Changing controls
To change the controls, use this:

--- Code: ---w::shift
--- End code ---
This example sets Shift to the w-key. In the same manner, you can set any key to any other. Just note that if you want to set your jump button to the Numpad, you need to deactivate numlock, otherwise you will constantly cancel your jumps (e.g. instead of setting jump to Numpad5, set it to NumpadClear)
Define each key in a new line, directly below the "#IfWinActive" stuff.
To make one key do nothing:

--- Code: ---q::return
--- End code ---

Changing window size and position
This just needs one line:

--- Code: ---Tab::WinMove,A,,290,0,1340,1045
--- End code ---
The first two numbers are the position of the windows (upper left corner), the last two numbers are the width and heigth. This example will resize the game to  1340x1045 pixels and put it in the center of the screen when you press Tab.

Changing the game volume
To do this easily with autohotkey, you need this nice little tool: nircmd (download at the bottom of the page). After downloading, run it once and choose to put it in the windows-directory. If you don't want to put it into the windows directory, just put the complete path into the code (e.g. "C:\stuff\nircmd.exe")

You can then use it in the ahk-script like this:

--- Code: ---^Up::run nircmd changeappvolume focused +0.1
^Down::run nircmd changeappvolume focused -0.1
--- End code ---
This examples lowers the volume of the active window by 10% when you press ctrl+down, and increases it with ctrl+Up.
If you want to set it directly to a predifined value, use setappvolume instead (e.g. setappvolume focused 0.1)
You can also combine this with resizing the window:

--- Code: ---Tab::
WinMove,A,,200,0,1340,1045
run nircmd setappvolume focused 0.1
return
--- End code ---

The complete script should look something like this:

--- Code: ---#MaxHotkeysPerInterval 9999

GroupAdd, Fangame, ahk_class TRunnerForm
GroupAdd, Fangame, ahk_class YYGameMakerYY
GroupAdd, Fangame, ahk_class Mf2MainClassTh

#IfWinActive ahk_group Fangame
{
a::Left
d::Right
w::Shift
s::Down
NumpadClear::Shift
NumpadLeft::z
NumpadRight::s
Space::r
Tab::
WinMove,A,,200,0,1340,1045
run nircmd setappvolume focused 0.1
return
}

--- End code ---
This is of course just an example. It's completely customizable for your needs.

I hope this helps someone :)

Edit:
you might also want to put this stuff to the top of the script. I don't know what it does, but it's supposed to increase performance:

--- Code: ---#NoEnv
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1

--- End code ---

Edit 2: If you experience problems with input lags, or anything else, try putting #UseHook somewhere above your hotkey.

Edit 3: more stuff in my next post :)

EternalMiluk:
This is really helpful! Thanks for your effort.

WatershameDave:
Exactly what I was looking for.

Mucho appreciato

Syd:
I just learned some new stuff  :atkHappy:

Make windows transparent

--- Code: ---F5::WinSet, Transparent, 150,A
F6::WinSet, Transparent, off,A
--- End code ---
The 150 in this example is the degree of opacity, so lowering it will make the window more transparent. The maximum opacity is 255.
This is useful when you want to recreate a room in jtool, as explained here. Note that unlike with ghostit, you have to make jtool transparent, not the game you are copying.

Make one color invisible

--- Code: ---F8::WinSet, TransColor, 000000, A
F6::WinSet, Transparent, off,A
--- End code ---
The number is the RGB value of the color you want to be invisible, in this case it's black. Very useful if you want to watch videos while playing fangames  :OneHand:
(click to show/hide)
edit: make color under mouse cursor invisible:
(click to show/hide)
--- Code: ---F8::
MakeInv(){
CoordMode, Pixel, Client
        CoordMode, Mouse, Client
        MouseGetPos, PosX,PosY
PixelGetColor, Color, %PosX%, %PosY%, RGB
WinSet, TransColor, %Color%, A
}
Return
--- End code ---

Remove titlebar and borders (so you can make the window a little bit bigger, without going fullscreen)

--- Code: ---F7::
WinSet, Style, ^0xC00000, A
WinSet, Style, ^0x40000, A
return
--- End code ---
the ^ makes it so it toggles on and off
edit: this will make GM:Studio games behave weirdly, and is also the reason why those don't like borderless fullscreen scripts

Borderless Fullscreen Script (not made by me)
(Note: doesn't work well with GM-Studio games, and I haven't found any other fullscreen-script that works for those)
(click to show/hide)
--- Code: ---F3::Toggle_Window(WinExist("A"))
Toggle_Window(Window:="") {
    static A := Init()
    if (!Window)
        MouseGetPos,,, Window
    WinGet, S, Style, % (i := "_" Window) ? "ahk_id " Window :  ; Get window style
    if (S & +0xC00000) {                                        ; If not borderless
        WinGet, IsMaxed, MinMax,  % "ahk_id " Window
        if (A[i, "Maxed"] := IsMaxed = 1 ? true : false)
            WinRestore, % "ahk_id " Window
        WinGetPos, X, Y, W, H, % "ahk_id " Window               ; Store window size/location
        for k, v in ["X", "Y", "W", "H"]
            A[i, v] := %v%
        Loop, % A.MCount {                                      ; Determine which monitor to use
            if (X >= A.Monitor[A_Index].Left
            &&  X <  A.Monitor[A_Index].Right
            &&  Y >= A.Monitor[A_Index].Top
            &&  Y <  A.Monitor[A_Index].Bottom) {
                WinSet, Style, -0xC00000, % "ahk_id " Window    ; Remove borders
WinSet, Style, -0x40000, % "ahk_id " Window    ; Including the resize border
                ; The following lines are the x,y,w,h of the maximized window
                ; ie. to offset the window 10 pixels up: A.Monitor[A_Index].Top - 10
                WinMove, % "ahk_id " Window,
                , A.Monitor[A_Index].Left                               ; X position
                , A.Monitor[A_Index].Top                                ; Y position
                , A.Monitor[A_Index].Right - A.Monitor[A_Index].Left    ; Width
                , A.Monitor[A_Index].Bottom - A.Monitor[A_Index].Top    ; Height
                break
            }
        }
    }
    else if (S & -0xC00000) {                                           ; If borderless
WinSet, Style, +0x40000, % "ahk_id " Window    ; Reapply borders
        WinSet, Style, +0xC00000, % "ahk_id " Window
        WinMove, % "ahk_id " Window,, A[i].X, A[i].Y, A[i].W, A[i].H    ; Return to original position
        if (A[i].Maxed)
            WinMaximize, % "ahk_id " Window
        A.Remove(i)
    }
}

--- End code ---

If you have any other ideas about what you could do with autohotkey regarding fangames, but don't know how to code it, post it here. Maybe I will find a way  :atkHappy:

Wolsk:
Autohotkey randomly deselects the window when I'm playing fangames sometimes, and I have no idea why.  I figured it'd be the same issue as what tenshots had but without the error message popping up, but adding #MaxHotkeysPerInterval 9999 did not seem to fix the issue for me.  The rest of my script is p much exactly what you have there.  Any ideas?

I know my script used to be a bit different from yours in regards to the ahk_class, and I don't remember having the random deselect issue until I changed it to match the example.  This is what my script looks like as of now:


--- Code: ---GroupAdd, Fangame, ahk_class TRunnerForm
GroupAdd, Fangame, ahk_class YYGameMakerYY
GroupAdd, Fangame, ahk_class Mf2MainClassTh

#IfWinActive ahk_group Fangame
{
LCtrl::LShift
RShift::LShift
Up::LShift
;Down::r
|::Send, {SHIFTUP}
~^d::Suspend
}
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version