Author Topic: [N/A] USB Gamepad To Key Input Script - Animehacker's Key Map Tool (1.0)  (Read 626 times)

animehacker

  • Newbie
  • *
  • Posts: 2
  • Karma: 2
    • View Profile
This is a script I wrote that will allow any USB gamepad such as a Playstation controller to work with any PC game regardless of driver support in the game.

I just bought FF7 again (Steam version) since I hadn't played it for years. I noticed that my x360 Controller Emulator software wouldn't work with it.

After some searching online I noticed there's other people who had the same problem. I'm not sure if a similar script/tool has been posted here but here is my solution.

1) Install AutoHotKey

2) Run my AHK script which should map your controller controls to the correct keyboard controls. I'm using a PS2 controller and it worked for me. You may need to replace '2Joy' with 'Joy' or '3Joy' in the script depending what your controller number is. If the script is working you can optionally compile it and run it as an executable if you don't want to keep AutoHotKey installed and it should still work fine.

3) (optional) To help you find your controller number or make other changes to my script you can debug using this great tool which runs as an AHK script.
https://autohotkey.com/docs/scripts/JoystickTest.ahk

Here is the script. Just copy paste into notepad and save it with the ahk extension e.g. 'FF7joy2key.ahk'. The key mappings are currently set to work with FF7 but can be modified for any game. This also allows you to move using the analogue stick on a dual shock controller.
Code: [Select]
#Persistent  ; Keep this script running until the user explicitly exits it.
SetTimer, WatchAxis, 5
return

WatchAxis:
GetKeyState, 2JoyX, 2JoyX  ; Get position of X axis.
GetKeyState, 2JoyY, 2JoyY  ; Get position of Y axis.
KeyToHoldDownPrev = %KeyToHoldDown%  ; Prev now holds the key that was down before (if any).

if 2JoyX > 70
    KeyToHoldDown = Right
else if 2JoyX < 30
    KeyToHoldDown = Left
else if 2JoyY > 70
    KeyToHoldDown = Down
else if 2JoyY < 30
    KeyToHoldDown = Up
else
    KeyToHoldDown =

if KeyToHoldDown = %KeyToHoldDownPrev%  ; The correct key is already down (or no key is needed).
    return  ; Do nothing.

; Otherwise, release the previous key and press down the new key:
SetKeyDelay -1  ; Avoid delays between keystrokes.
if KeyToHoldDownPrev   ; There is a previous key to release.
    Send, {%KeyToHoldDownPrev% up}  ; Release it.
if KeyToHoldDown   ; There is a key to press down.
    Send, {%KeyToHoldDown% down}  ; Press it down.
return
2Joy3::
Send {NUMPADENTER down}
KeyWait 2Joy3
Send {NUMPADENTER up} 
return
2Joy2::
Send {NUMPADINS down}
KeyWait 2Joy2 
Send {NUMPADINS up} 
return
2Joy1::
Send {NUMPADADD down}
KeyWait 2Joy1 
Send {NUMPADADD up} 
return
2Joy4::
Send {NUMPADDEL down}
KeyWait 2Joy1 
Send {NUMPADDEL up} 
return
2Joy9::
Send {NUMPADSUB down}
KeyWait 2Joy9
Send {NUMPADSUB up} 
return
2Joy10::
Send {NUMPAD5 down}
KeyWait 2Joy10 
Send {NUMPAD5 up} 
return
2Joy6::
Send {NUMPAD1 down}
KeyWait 2Joy6 
Send {NUMPAD1 up} 
return
2Joy5::
Send {NUMPAD7 down}
KeyWait 2Joy5
Send {NUMPAD7 up} 
return
2Joy7::
Send {NUMPAD9 down}
KeyWait 2Joy7
Send {NUMPAD9 up} 
return
2Joy8::
Send {NUMPAD3 down}
KeyWait 2Joy8
Send {NUMPAD3 up} 
return
« Last Edit: 2017-04-16 18:31:14 by animehacker »

Covarr

  • Covarr-Let
  • Administrator
  • No life
  • *
  • Posts: 3917
  • Karma: 115
  • The Great Redarr.
    • View Profile
I hate to be a bummer, but I'm not sure how much of a problem this is anymore for most FF7 users now that Steam can do this itself with any controller (it used to only work with the Steam Controller). You can have arbitrary configurations per-game.

Even for people who aren't using Steam, this has been done many times in the past with tools like:

  • Joy2Key (Free, GPL) - Discontinued, and not the best software, but it's free and it works. Might have trouble on newer systems. Seems to have been supplanted by a paid fork.
  • Pinnacle Game Profiler (On sale for $6, possibly permanent) - This was my recommendation until Steam added mapping. Still good software, years of profiles, but maybe not worth the money to everyone when there's free options available.
  • Xpadder ($10) - It works, but the UI is junk. I'm slow to recommend this to anyone, but some people swear by it.
  • AntiMicro (Free, GPL) - I haven't used this, but it looks to be pretty good software. Probably the best choice for people who don't want to use commercial software or Steam.

Personally, Steam's is my favorite because for games that DO support gamepads it's really easy to remap only some of the buttons. Want to swap X and O, without changing anything else? Easy. Want to make the left stick double as the D-Pad in a game with no analog support? Easy peasy.

Don't get the wrong idea; I do think there's merit behind an AHK-based solution. It's very lightweight. For someone who knows AHK, it's more configurable than anything else. A little bit of know-how, and someone could set up all kinds of crazy things, rapidfire, etc. But I don't know how many people will be interested in this except those that already use AutoHotKey.

animehacker

  • Newbie
  • *
  • Posts: 2
  • Karma: 2
    • View Profile
Hi there Covarr, thanks for the good reply.

I tried using the Steam Big Picture mode setup and it was able to detect the controller and setup the keys fine. Unfortunately Final Fantasy 7 was only able to detect some of the key presses like arrow keys but none of the normal buttons with my PSX dual shock controller. I'm sure it works for some people.

I think my script might still be useful for some people as at the moment it's the only free solution I have found that works for me. Hopefully there might still be some people out there that find it useful :)

Great forum by the way! I really appreciate that you haven't covered it in advertising banners.