4

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
}
vaindil
  • 1,289

2 Answers2

4
  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).

  • #IfWinActive is exactly what I needed, thank you! However, the second part is not working. Having SendMode Play caused AHK to have no effect in the game, but using any of the other options caused the exact same results as in my original post. – vaindil Nov 04 '13 at 21:15
  • @StevenH, I've adapted my answer a litte. Hope this helps. – user 99572 is fine Nov 18 '13 at 12:37
1

It looks like you have keys mapped to each other which can cause circular calling. Try putting a $ in front of each of your keys. That will prevent that problem.

Example:

$w::up

Source

Regarding your IfWinActive issue, I would suggest using ahk_exe instead. Just look up the process name in Task Manager and put the following line before all of your hotkeys.

#If WinActive("ahk_exe rayman.exe")  ; Rename exe to whatever it really is

Source