Jump to content

Game Key Modifications


Recommended Posts

OK, I have FF7 for the PC. I am trying to write a script to change the keys in-game (ex. Up, Down). The game is hard coded to only use the number pad for all of the keys. There are no options to change this.

The issue that I'm having may not be solvable with AutoIt. I have tried using HotKeySet along with a function that send the keystroke to the game which corresponds with the number pad.

Here are the problems:

  • When walking using "w" (or any other key), the key sticks and continues walking after I release.
  • I am unable to use multiple keys at a time (such as "w" & "a") to move diagonal.

The code I use is:

;----These are the AutoIt options I have set. (still playing around with these)
Opt("SendKeyDelay",5)
Opt("SendKeyDownDelay", 60)

;---- Reads all of the keys from an INI file.
$key[1][0] = IniRead($save, "Keys", "Up", "w")
$key[2][0] = IniRead($save, "Keys", "Down", "s")
$key[3][0] = IniRead($save, "Keys", "Left", "a")
$key[4][0] = IniRead($save, "Keys", "Right", "d")
$key[5][0] = IniRead($save, "Keys", "OK", "c")
$key[6][0] = IniRead($save, "Keys", "Cancel", "x")
$key[7][0] = IniRead($save, "Keys", "Menu", "v")
$key[8][0] = IniRead($save, "Keys", "Switch", "{tab}")
$key[9][0] = IniRead($save, "Keys", "PUp", "q")
$key[10][0] = IniRead($save, "Keys", "PDown", "e")
$key[11][0] = IniRead($save, "Keys", "View", "f")
$key[12][0] = IniRead($save, "Keys", "Run", "r")
$key[13][0] = IniRead($save, "Keys", "Target", "t")
$key[14][0] = IniRead($save, "Keys", "Start", "p")
$key[15][0] = IniRead($save, "Keys", "Assist", "z")
$key[16][0] = IniRead($save, "Keys", "Quit", "")

;---- These are the Hard coded Number Pad references.
$key[1][1] = "{numpad8}"
$key[2][1] = "{numpad2}"
$key[3][1] = "{numpad4}"
$key[4][1] = "{numpad6}"
$key[5][1] = "{numpadenter}"
$key[6][1] = "{numpad0}"
$key[7][1] = "{numpadadd}"
$key[8][1] = "{numpaddot}"
$key[9][1] = "{numpad9}"
$key[10][1] = "{numpad3}"
$key[11][1] = "{numpad7}"
$key[12][1] = "{numpad7}{numpad3}"
$key[13][1] = "{numpad1}"
$key[14][1] = "{numpad5}"
$key[15][1] = "{numpadsub}"
$key[16][1] = ""

;---- Here loads the game settings along with the game, then sets the hotkeys.
;---- The Hotkyes unload once the game is minimized or quit.

for $i=1 to 16 step 1
    HotKeySet($key[$i][0],"Sendkey")
Next

;---- This is the function I use to emulate the Number Pad.

Func SendKey()
    $loc=_ArraySearch($key, @HotKeyPressed)
    Send($key[$loc][1])
EndFunc

This is a small piece of the script I have. If more is needed, please let me know. These are all options that deal with the Keystrokes. Single keystrokes work fine; but the game is a pain to play not being able to use multiple keys as input.

Thanks for taking a look!

Link to comment
Share on other sites

However simple this is, there is no offical PC version of Final Fantasy VII. So I'll assume that your copy isn't legal.

Actually

http://en.wikipedia.org/wiki/Final_Fantasy_VII

I use to be a huge fan. Decided I wanted to get back into it, so I found a copy.

Link to comment
Share on other sites

Ok, I've been playing around with some code and came up with something that halfway works. I started using _IsPressed instead of HotKeySet.

#include <Array.au3>
#include <Misc.au3>
Opt("SendKeyDelay", 0)
Opt("SendKeyDownDelay", 200)

Global $key[17][3]
Global $save = @ScriptDir & "\FF7 Loader.ini"
Global $sethotkeys = 1
Global $LsettingsGUI, $KeyGui, $allKeys, $runkeycapture=1

$key[1][0] = IniRead($save, "Keys", "Up", "w")
$key[2][0] = IniRead($save, "Keys", "Down", "s")
$key[3][0] = IniRead($save, "Keys", "Left", "a")
$key[4][0] = IniRead($save, "Keys", "Right", "d")
$key[5][0] = IniRead($save, "Keys", "OK", "c")
$key[6][0] = IniRead($save, "Keys", "Cancel", "x")
$key[7][0] = IniRead($save, "Keys", "Menu", "v")
$key[8][0] = IniRead($save, "Keys", "Switch", "{tab}")
$key[9][0] = IniRead($save, "Keys", "PUp", "q")
$key[10][0] = IniRead($save, "Keys", "PDown", "e")
$key[11][0] = IniRead($save, "Keys", "View", "f")
$key[12][0] = IniRead($save, "Keys", "Run", "r")
$key[13][0] = IniRead($save, "Keys", "Target", "t")
$key[14][0] = IniRead($save, "Keys", "Start", "p")
$key[15][0] = IniRead($save, "Keys", "Assist", "z")
$key[16][0] = IniRead($save, "Keys", "Quit", "")

$key[1][1] = "{numpad8}"
$key[2][1] = "{numpad2}"
$key[3][1] = "{numpad4}"
$key[4][1] = "{numpad6}"
$key[5][1] = "{numpadenter}"
$key[6][1] = "{numpad0}"
$key[7][1] = "{numpadadd}"
$key[8][1] = "{numpaddot}"
$key[9][1] = "{numpad9}"
$key[10][1] = "{numpad3}"
$key[11][1] = "{numpad7}"
$key[12][1] = "{numpad7}{numpad3}"
$key[13][1] = "{numpad1}"
$key[14][1] = "{numpad5}"
$key[15][1] = "{numpadsub}"
$key[16][1] = ""

;-------------Start Key Modification Here
keycapture()

While 1
    sleep(100)
WEnd

;------------Keep track of what key is pressed and add to a variable
;------------I have listed all keys so the user can use any key he wants in the ini file.
Func keycapture()
    $hDll = DllOpen("user32.dll")
    While $runkeycapture = 1
        If _IsPressed(41, $hDll) Then
            $allKeys &= "a|"
        EndIf

        If _IsPressed(42, $hDll) Then
            $allKeys &= "b|"
        EndIf

        If _IsPressed(43, $hDll) Then
            $allKeys &= "c|"
        EndIf

        If _IsPressed(44, $hDll) Then
            $allKeys &= "d|"
        EndIf

        If _IsPressed(45, $hDll) Then
            $allKeys &= "e|"
        EndIf

        If _IsPressed(46, $hDll) Then
            $allKeys &= "f|"
        EndIf

        If _IsPressed(47, $hDll) Then
            $allKeys &= "g|"
        EndIf

        If _IsPressed(48, $hDll) Then
            $allKeys &= "h|"
        EndIf

        If _IsPressed(49, $hDll) Then
            $allKeys &= "i|"
        EndIf

        If _IsPressed('4a', $hDll) Then
            $allKeys &= "j|"
        EndIf

        If _IsPressed('4b', $hDll) Then
            $allKeys &= "k|"
        EndIf

        If _IsPressed('4c', $hDll) Then
            $allKeys &= "l|"
        EndIf

        If _IsPressed('4d', $hDll) Then
            $allKeys &= "m|"
        EndIf

        If _IsPressed('4e') = 1 Then
            $allKeys &= "n|"
        EndIf

        If _IsPressed('4f', $hDll) Then
            $allKeys &= "o|"
        EndIf

        If _IsPressed(50) Then
            $allKeys &= "p|"
        EndIf

        If _IsPressed(51) Then
            $allKeys &= "q|"
        EndIf

        If _IsPressed(52) Then
            $allKeys &= "r|"
        EndIf

        If _IsPressed(53) Then
            $allKeys &= "s|"
        EndIf

        If _IsPressed(54) Then
            $allKeys &= "t|"
        EndIf

        If _IsPressed(55) Then
            $allKeys &= "u|"
        EndIf

        If _IsPressed(56) Then
            $allKeys &= "v|"
        EndIf

        If _IsPressed(57) Then
            $allKeys &= "w|"
        EndIf

        If _IsPressed(58) Then
            $allKeys &= "x|"
        EndIf

        If _IsPressed(59) Then
            $allKeys &= "y|"
        EndIf

        If _IsPressed('5a', $hDll) Then
            $allKeys &= "z|"
        EndIf

        If _IsPressed('01', $hDll) Then
            $allKeys &= "{LEFT MOUSE}|"
        EndIf

        If _IsPressed('02', $hDll) Then
            $allKeys &= "{RIGHT MOUSE}|"
        EndIf

        If _IsPressed('08', $hDll) Then
            $allKeys &= "{BACKSPACE}|"
        EndIf

        If _IsPressed('09', $hDll) Then
            $allKeys &= "{TAB}|"
        EndIf

        If _IsPressed('0d', $hDll) Then
            $allKeys &= "{ENTER}|"
        EndIf

        If _IsPressed('10', $hDll) Then
            $allKeys &= "{LSHIFT}|"
        EndIf

        If _IsPressed('11', $hDll) Then
            $allKeys &= "{LCTRL}|"
        EndIf

        If _IsPressed('12', $hDll) Then
            $allKeys &= "{ALT}|"
        EndIf

        If _IsPressed('13', $hDll) Then
            $allKeys &= "{PAUSE}|"
        EndIf

        If _IsPressed('14', $hDll) Then
            $allKeys &= "{CAPSLOCK}|"
        EndIf

        If _IsPressed('1b', $hDll) Then
            $allKeys &= "{ESC}|"
        EndIf

        If _IsPressed('20', $hDll) Then
            $allKeys &= " |"
        EndIf

        If _IsPressed('21', $hDll) Then
            $allKeys &= "{PGUP}|"
        EndIf

        If _IsPressed('22', $hDll) Then
            $allKeys &= "{PGDN}|"
        EndIf

        If _IsPressed('23', $hDll) Then
            $allKeys &= "{END}|"
        EndIf

        If _IsPressed('24', $hDll) Then
            $allKeys &= "{HOME}|"
        EndIf

        If _IsPressed('25', $hDll) Then
            $allKeys &= "{LEFT}|"
        EndIf

        If _IsPressed('26', $hDll) Then
            $allKeys &= "{UP}|"
        EndIf

        If _IsPressed('27', $hDll) Then
            $allKeys &= "{RIGHT}|"
        EndIf

        If _IsPressed('28', $hDll) Then
            $allKeys &= "{DOWN}|"
        EndIf

        If _IsPressed('2c', $hDll) Then
            $allKeys &= "{PRINTSCREEN}|"
        EndIf

        If _IsPressed('2d', $hDll) Then
            $allKeys &= "{INSERT}|"
        EndIf

        If _IsPressed('2e', $hDll) Then
            $allKeys &= "{DEL}|"
        EndIf

        If _IsPressed('30', $hDll) Then
            $allKeys &= "0|"
        EndIf

        If _IsPressed('31', $hDll) Then
            $allKeys &= "1|"
        EndIf

        If _IsPressed('32', $hDll) Then
            $allKeys &= "2|"
        EndIf

        If _IsPressed('33', $hDll) Then
            $allKeys &= "3|"
        EndIf

        If _IsPressed('34', $hDll) Then
            $allKeys &= "4|"
        EndIf

        If _IsPressed('35', $hDll) Then
            $allKeys &= "5|"
        EndIf

        If _IsPressed('36', $hDll) Then
            $allKeys &= "6|"
        EndIf

        If _IsPressed('37', $hDll) Then
            $allKeys &= "7|"
        EndIf

        If _IsPressed('38', $hDll) Then
            $allKeys &= "8|"
        EndIf

        If _IsPressed('39', $hDll) Then
            $allKeys &= "9|"
        EndIf
        _KeyIsPressed($allKeys)
        $allKeys = ""
    WEnd
    DllClose($hDll)
EndFunc   ;==>keycapture


;----------Track keys pressed and find them in an array of defined keys.
;----------If found, add the numberpad variant to a Send command.
;----------I added the 'Down' and 'Up' to the Send string to try and simulate diagonal instead of left then up.

Func _KeyIsPressed($keypressed)
    Local $keysSend = "", $keyArray = "", $keysfound = "", $relSend = ""
    $keyArray = StringSplit($allKeys, "|")
    For $i = 1 To $keyArray[0] Step 1
        $keysfound = _ArraySearch($key,$keyArray[$i])
        If Not @error Then
            $keysSend &= $key[$keysfound][1]
        EndIf
    Next
    if StringInStr($keysSend, "}") Then
        $keysSend=StringReplace($keysSend, "}", " Down}")
        $relSend=StringReplace($keysSend, "Down", "Up")
        Send($keysSend&$relSend)
    EndIf
EndFunc   ;==>_KeyIsPressed

I marked comments in the code to show my intentions. The problem I'm getting is when AutoIt sends the keys back UP. The movement of the character becomes "Jagged" and he seems to start and stop quickly. The SendKeyDownDelay seems to help, but I don't know how to tell AutoIt to "only send the key UP if I let go". I'll continue to look into it myself, but I'm hoping that someone knows an easy way.

Edited by cloudd901
Link to comment
Share on other sites

I have the script finished, but I may need some help cleaning it up a bit. (Marked comments in code.)

#include <Array.au3>
#include <Misc.au3>
Global $save = @ScriptDir & "\FF7 Loader.ini"
Global $start = 0, $mount = 0, $Pause = 0, $GameConfig = 0, $Backupstring, $runkeycapture = 1
Global $LsettingsGUI, $KeyGui, $allKeys, $keyBackup
Global $radio1, $radio2, $radio3, $radio4, $radio5
Global $key[17][3]

;=========================These keys have an INI and GUI interface that can be set to any keys.
$key[1][0] = IniRead($save, "Keys", "Up", "w")
$key[2][0] = IniRead($save, "Keys", "Down", "s")
$key[3][0] = IniRead($save, "Keys", "Left", "a")
$key[4][0] = IniRead($save, "Keys", "Right", "d")
$key[5][0] = IniRead($save, "Keys", "OK", "c")
$key[6][0] = IniRead($save, "Keys", "Cancel", "{lshift}")
$key[7][0] = IniRead($save, "Keys", "Menu", "v")
$key[8][0] = IniRead($save, "Keys", "Switch", "{tab}")
$key[9][0] = IniRead($save, "Keys", "PUp", "q")
$key[10][0] = IniRead($save, "Keys", "PDown", "e")
$key[11][0] = IniRead($save, "Keys", "View", "f")
$key[12][0] = IniRead($save, "Keys", "Run", "r")
$key[13][0] = IniRead($save, "Keys", "Target", "t")
$key[14][0] = IniRead($save, "Keys", "Start", "p")
$key[15][0] = IniRead($save, "Keys", "Assist", "z")
$key[16][0] = IniRead($save, "Keys", "Quit", "")

;=========================These are the keys that autoit actually presses to make the character move.
$key[1][1] = "{numpad8}"
$key[2][1] = "{numpad2}"
$key[3][1] = "{numpad4}"
$key[4][1] = "{numpad6}"
$key[5][1] = "{numpadenter}"
$key[6][1] = "{numpad0}"
$key[7][1] = "{numpadadd}"
$key[8][1] = "{numpaddot}"
$key[9][1] = "{numpad9}"
$key[10][1] = "{numpad3}"
$key[11][1] = "{numpad7}"
$key[12][1] = "{numpad7}{numpad3}"
$key[13][1] = "{numpad1}"
$key[14][1] = "{numpad5}"
$key[15][1] = "{numpadsub}"
$key[16][1] = ""
$sticky = RegRead("HKEY_CURRENT_USER \Control Panel \Accessibility \StickyKeys", "Flags")

;=========================Start running the key script here. I place this after the run command for the game.
keycapture()
While 1
    Sleep(100)
WEnd
Func keycapture()
;=========================Disable the Sticky Keys for using buttons like shift or ctrl.
    RegWrite("HKEY_CURRENT_USER \Control Panel \Accessibility \StickyKeys", "Flags", "REG_SZ", 506)
    $hDll = DllOpen("user32.dll")
    While $runkeycapture = 1
        If _IsPressed(41, $hDll) Then
            $allKeys &= "a|"
        EndIf
        If _IsPressed(42, $hDll) Then
            $allKeys &= "b|"
        EndIf
        If _IsPressed(43, $hDll) Then
            $allKeys &= "c|"
        EndIf
        If _IsPressed(44, $hDll) Then
            $allKeys &= "d|"
        EndIf
        If _IsPressed(45, $hDll) Then
            $allKeys &= "e|"
        EndIf
        If _IsPressed(46, $hDll) Then
            $allKeys &= "f|"
        EndIf
        If _IsPressed(47, $hDll) Then
            $allKeys &= "g|"
        EndIf
        If _IsPressed(48, $hDll) Then
            $allKeys &= "h|"
        EndIf
        If _IsPressed(49, $hDll) Then
            $allKeys &= "i|"
        EndIf
        If _IsPressed('4a', $hDll) Then
            $allKeys &= "j|"
        EndIf
        If _IsPressed('4b', $hDll) Then
            $allKeys &= "k|"
        EndIf
        If _IsPressed('4c', $hDll) Then
            $allKeys &= "l|"
        EndIf
        If _IsPressed('4d', $hDll) Then
            $allKeys &= "m|"
        EndIf
        If _IsPressed('4e') = 1 Then
            $allKeys &= "n|"
        EndIf
        If _IsPressed('4f', $hDll) Then
            $allKeys &= "o|"
        EndIf
        If _IsPressed(50) Then
            $allKeys &= "p|"
        EndIf
        If _IsPressed(51) Then
            $allKeys &= "q|"
        EndIf
        If _IsPressed(52) Then
            $allKeys &= "r|"
        EndIf
        If _IsPressed(53) Then
            $allKeys &= "s|"
        EndIf
        If _IsPressed(54) Then
            $allKeys &= "t|"
        EndIf
        If _IsPressed(55) Then
            $allKeys &= "u|"
        EndIf
        If _IsPressed(56) Then
            $allKeys &= "v|"
        EndIf
        If _IsPressed(57) Then
            $allKeys &= "w|"
        EndIf
        If _IsPressed(58) Then
            $allKeys &= "x|"
        EndIf
        If _IsPressed(59) Then
            $allKeys &= "y|"
        EndIf
        If _IsPressed('5a', $hDll) Then
            $allKeys &= "z|"
        EndIf
        If _IsPressed('01', $hDll) Then
            $allKeys &= "{LEFT MOUSE}|"
        EndIf
        If _IsPressed('02', $hDll) Then
            $allKeys &= "{RIGHT MOUSE}|"
        EndIf
        If _IsPressed('08', $hDll) Then
            $allKeys &= "{BACKSPACE}|"
        EndIf
        If _IsPressed('09', $hDll) Then
            $allKeys &= "{TAB}|"
        EndIf
        If _IsPressed('0d', $hDll) Then
            $allKeys &= "{ENTER}|"
        EndIf
        If _IsPressed('10', $hDll) Then
            $allKeys &= "{LSHIFT}|"
        EndIf
        If _IsPressed('11', $hDll) Then
            $allKeys &= "{LCTRL}|"
        EndIf
        If _IsPressed('12', $hDll) Then
            $allKeys &= "{ALT}|"
        EndIf
        If _IsPressed('13', $hDll) Then
            $allKeys &= "{PAUSE}|"
        EndIf
        If _IsPressed('14', $hDll) Then
            $allKeys &= "{CAPSLOCK}|"
        EndIf
        If _IsPressed('1b', $hDll) Then
            $allKeys &= "{ESC}|"
        EndIf
        If _IsPressed('20', $hDll) Then
            $allKeys &= " |"
        EndIf
        If _IsPressed('21', $hDll) Then
            $allKeys &= "{PGUP}|"
        EndIf
        If _IsPressed('22', $hDll) Then
            $allKeys &= "{PGDN}|"
        EndIf
        If _IsPressed('23', $hDll) Then
            $allKeys &= "{END}|"
        EndIf
        If _IsPressed('24', $hDll) Then
            $allKeys &= "{HOME}|"
        EndIf
        If _IsPressed('25', $hDll) Then
            $allKeys &= "{LEFT}|"
        EndIf
        If _IsPressed('26', $hDll) Then
            $allKeys &= "{UP}|"
        EndIf
        If _IsPressed('27', $hDll) Then
            $allKeys &= "{RIGHT}|"
        EndIf
        If _IsPressed('28', $hDll) Then
            $allKeys &= "{DOWN}|"
        EndIf
        If _IsPressed('2c', $hDll) Then
            $allKeys &= "{PRINTSCREEN}|"
        EndIf
        If _IsPressed('2d', $hDll) Then
            $allKeys &= "{INSERT}|"
        EndIf
        If _IsPressed('2e', $hDll) Then
            $allKeys &= "{DEL}|"
        EndIf
        If _IsPressed('30', $hDll) Then
            $allKeys &= "0|"
        EndIf
        If _IsPressed('31', $hDll) Then
            $allKeys &= "1|"
        EndIf
        If _IsPressed('32', $hDll) Then
            $allKeys &= "2|"
        EndIf
        If _IsPressed('33', $hDll) Then
            $allKeys &= "3|"
        EndIf
        If _IsPressed('34', $hDll) Then
            $allKeys &= "4|"
        EndIf
        If _IsPressed('35', $hDll) Then
            $allKeys &= "5|"
        EndIf
        If _IsPressed('36', $hDll) Then
            $allKeys &= "6|"
        EndIf
        If _IsPressed('37', $hDll) Then
            $allKeys &= "7|"
        EndIf
        If _IsPressed('38', $hDll) Then
            $allKeys &= "8|"
        EndIf
        If _IsPressed('39', $hDll) Then
            $allKeys &= "9|"
        EndIf
        _KeyIsPressed($allKeys)
        $allKeys = ""
    WEnd
    DllClose($hDll)
    RegWrite("HKEY_CURRENT_USER \Control Panel \Accessibility \StickyKeys", "Flags", "REG_SZ", $sticky)
EndFunc   ;==>keycapture

;=================I found that if I set a backup keystring and compair it to the new keystring, I can find out
;=================  what keys were released. Then I use "Down" to simulate the keypress and "Up" to simulate the keyrelease.

Func _KeyIsPressed($allKeys)
    Local $keysSend = "", $keyArray = "", $keysfound = "", $relSend = "", $locstring = ""
    $keyArray = StringSplit($allKeys, "|")
    For $i = 1 To $keyArray[0] Step 1
        $keysfound = _ArraySearch($key, $keyArray[$i])
        If Not @error Then
            $keysSend &= $key[$keysfound][1]
        EndIf
    Next
    If StringInStr($keysSend, "}") Then
        $keysSend = StringReplace($keysSend, "}", " Down}")
    EndIf
    $kstring1 = StringSplit($keysSend, "}")
    $kstring2 = StringSplit($Backupstring, "}")
    For $i = $kstring1[0] To 1 Step -1
        $loc = _ArraySearch($kstring2, $kstring1[$i])
        If Not @error Then _ArrayDelete($kstring2, $loc)
    Next
    $Backupstring = _ArrayToString($kstring2, "}", 1)
    If Not @error Then $Backupstring &= "}"
    If StringInStr($Backupstring, "Down") Then
        $relSend = StringReplace($Backupstring, "Down", "Up")
    EndIf
;=========================Added msgbox to view what keys will be sent to the game.
;~  Send($relSend)
;~  Send($keysSend)
MsgBox(0, "", $keysSend&"|"&$relSend)
    $Backupstring = $keysSend
EndFunc   ;==>_KeyIsPressed

This solves the issue I was having. This allows the character to continue walking if I hold down a key; and stop walking if I release a key. Also accepts multiple keystrokes at once using 'Down' with Send().

If anyone would know how to clean it up a bit or if anyone knows another, quicker, way of doing this; please let me know.

The only issue I've ran into so far using this script is the fact that it doesn't always release the "lshift" key. I tried temporarily disabling 'StickyKeys' in the registry and seemed to help it work better. But after holding it for a while; I am still forced to press it again a couple of times to get it to unstick. Is there another reg option for sticky keys?

Thanks again,

Hope this code can be usefull to someone else as well.

My complete FF7 Loader is about 1k lines. I use it to make my FF7PC installation portable.

Edited by cloudd901
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...