Using AutoHotKey to remap keys

I recently purchased Rayman 2 from GOG.com. The game is old and thus does not give the option to remap keys, and I’d like to make them a little closer to what we’re used to today.

Here's a screenshot from the manual with the key bindings.

Basically, I want normal movement with WSAD, jump with space, and shoot with left mouse click. Also, I’d like the keys to only be remapped when the Rayman window is active. I created the below script, but it does not work correctly.

This is the first time I’ve ever worked with AHK, so I’m not sure what to do. How can I correctly configure the script?

Here’s what happens with this script active:

  • Script is active whether Rayman is open or not, let alone whether the window is active. (The window name can either be Rayman II or Rayman2.)
  • W: moves forward and turns camera to the right
  • S: works as intended
  • A: moves left and jumps
  • D: works as intended
  • LButton: works as intended
  • space: shoots and jumps

The script itself:

IfWinActive, Rayman2
{
    w::up
    s::down
    a::left
    d::right
    space::a
    LButton::space
}

Answer

  1. First, you’re using the wrong command. Use #IfWinActive. This is for the whole script. The command you chose checks if a window is active within a script.
  2. Then, check with WindowSpy what the ahk_class of the window is (which is useful if the window title changes). WindowSpy is included in the AutoHotkey installation.
  3. Last, try different SendModes. There are a few that vary in the details. More info on the different Send commands can be found here.

Your code will look something like this:

#IfWinActive, ahk_class xyz ; put your ahk_class instead of xyz
SendMode Play ; try all of the following: Input|Play|Event|InputThenPlay

    w::up
    s::down
    a::left
    d::right
    space::a
    LButton::space

Qualification: Depending on the Windows version you’re using, simulating key presses may or may not work. What works up to Windows 7, may not work in Windows 8 anymore. It has happened to me too and I haven’t figured out an alternative within AutoHotkey yet.

You may need to try a different macro software (AutoIt, PhraseExpress, Macro Express).

Attribution
Source : Link , Question Author : vaindil , Answer Author : user 99572 is fine

Leave a Comment