Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Analog Joystick or Arrow Keys to Mouse Movement? for RE4


  • Please log in to reply
11 replies to this topic
Tw1tch
  • Members
  • 8 posts
  • Last active: Oct 16 2008 04:35 PM
  • Joined: 25 Jun 2007
Hello everyone, just came across the AHK program in my search for mouse support for Resident Evil 4 for the PC. The game by default (ver. 1.1 US rel) has no mouse support, nor is there an available patch for it. It does, however, function with aiming via an analog joystick or using the arrow keys to aim.

My question is if the AutoHotKey program can allow the mapping of the joystick analog movement or the regular arrow keys to direct mouse movement? This would allow a hot fix of sorts to be able to aim in Resident Evil 4 the same as in any FPS game.

So far I've tried the following script, but with no luck:
MouseMove, 0, -10, 0, R::up
MouseMove, 0, 10, 0, R::down
MouseMove, -10, 0, 0, R::left
MouseMove, 10, 0, 0, R::right

The script does function backwards, allowing my arrow keys to navigate the mouse cursor. Unfortunately though, that is the opposite of what I'm looking for.

Any help is greatly appreciated. Thanks.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
:: is a hotkey identifier, you can't have a command like MouseMove to the left of it.

This sort of works, but I don't have a game to test it on... Hit F6 to make it start and Escape to make it stop, since it otherwise takes over your mouse. You also need to fill in the program name (multiple AddGroup lines are allowed if you want it for more than one program)

#persistent
#singleInstance force
CoordMode, Pixel, Mouse
GroupAdd, MyGroup, PUT PROGRAM NAME HERE

homeX = 300
homeY = 300
return

F6::
Settimer, checkmouse, 100

return

checkmouse:
IfWinActive, ahk_group MyGroup
{
  MouseGetPos, curX, curY
  If (curX-homeX > 5)
    Send {right}
  If (curX-homeX < -5)
    Send {left}
  If (curY-homeY > 5)
    Send {down}
  If (curY-homeY < -5)
    Send {up}
  MouseMove, %homeX%, %homeY% , 0
  ;tooltip, % prevX . " " . curX . " " . prevY . " " . curY, 20,20
}
eturn

Esc::ExitApp


Tw1tch
  • Members
  • 8 posts
  • Last active: Oct 16 2008 04:35 PM
  • Joined: 25 Jun 2007
Thanks for the help, although it doesn't work for me. The only error in the code I could find was the "eturn" which I changed to "return". Otherwise the scripting for this is a bit out of my league, so Im not sure where to go.

I tried the standard script you wrote which I couldnt get to work. Then I tried to do away with the on/off-F6/Escape and still no dice. I tried the program name "notepad" and also the RE4 .exe. I took it one step further and tried to use it on all of Windows, using "GroupAdd, AllWindows", and still nothing.

I'll try and think of something else, and thanks again.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
The "program name" should actually be the window name (i.e. "Untitled - Notepad" instead of "notepad".) By default, "notepad" will match any windows with titles starting with "notepad". (Look up SetTitleMatchMode in the help file.)

The script seems to work in notepad if I replace
GroupAdd, MyGroup, PUT PROGRAM NAME HERE
with
GroupAdd, MyGroup, ahk_class Notepad
("ahk_class notepad" matches all notepad windows, regardless of title.)

I assume where engunneer wrote
CoordMode, Pixel, Mouse
he actually meant
CoordMode, Mouse, Screen
to make the MouseGetPos and MouseMove coords relative to the screen rather than the active window.

Strangely, the Esc::ExitApp hotkey doesn't work for me... If I press Escape, the script only exits after I press Ctrl+Alt+Delete. :?

whygnat
  • Members
  • 3 posts
  • Last active: Jul 29 2007 07:13 PM
  • Joined: 01 Apr 2007
hmmm... I don't think re4 is taking what Autohotkey is sending. I got a modified version of the posted script to work in the normal windows (notebook, etc) but re4 wont accept the Send. I tried various sends... sendraw, sendinput, etc and none of them were accepted. Re4 can handle remapped keys so I can set f8::a and what's-his-face turns left when I hit f8. That's no help.

Will play some more but, even if it accepts these sends, it's still not a real PC mouse input. Shooters that use the mouse accept a fast swipe as turning quickly and a slow swipe as careful aiming. RE4 will only take "turn left" at one speed.

I just hope Capcom gets their head out of their you know what and posts a patch.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
[quote name="whygnat"]hmmm... I don't think re4 is taking what Autohotkey is sending. I got a modified version of the posted script to work in the normal windows (notebook, etc) but re4 wont accept the Send. I tried various sends... sendraw, sendinput, etc and none of them were accepted. Re4 can handle remapped keys so I can set f8::a and what's-his-face turns left when I hit f8. That's no help.[/quote]
If F8::a works, send should also work.
[quote name="help]When a script is launched, each remapping is translated into a pair of hotkeys. For example, a script containing a::b actually contains the following two hotkeys instead:
*a::
SetKeyDelay -1   ; If the destination key is a mouse button, SetMouseDelay is used instead.
Send {Blind}{b DownTemp}  ; DownTemp is like Down except that other Send commands in the script won't assume "b" should stay down during their Send.
return

*a up::
SetKeyDelay -1  ; See note below for why press-duration is not specified with either of these SetKeyDelays.
Send {Blind}{b Up}
return
[/quote]
If you're simply sending keypresses (i.e. Send {Left}), you probably need to add a delay; like:
Send {Left Down}
Sleep, 50 ; may need adjustment
Send {Left Up}
This is because many games poll for input only once per game loop/frame. If it runs at 30 frames per second, that's rougly every 33 milliseconds (1/30). The problem with the above code is that the sleep may reduce the responsiveness of your script, so timers might work better:
Send {Left Down}
SetTimer, LeftUp, -50 ; execute once in 50 ms
return
LeftUp:
Send {Left Up}
return
[quote]even if it accepts these sends, it's still not a real PC mouse input. Shooters that use the mouse accept a fast swipe as turning quickly and a slow swipe as careful aiming. RE4 will only take "turn left" at one speed.[/quote]Too right. If RE4 accepts analog joystick input for aiming, you could try PPJoy, which is able to emulate one or more joysticks. Specifically, look for Supported interfaces -> Virtual joysticks -> PPJoyMouse in the side-menu. (You'll need to install PPJoy and configure a virtual joystick before using PPJoyMouse.)

whygnat
  • Members
  • 3 posts
  • Last active: Jul 29 2007 07:13 PM
  • Joined: 01 Apr 2007
Thanks for the insights, lexikos. I've done some stuff with AHK but it eludes me at times when operating games and such. The lexikos method with the timer sort of works but it's pretty herky-jerky... even tweaking the timings, the guy studder turns.

What was closer was to just keeping the key down until the mouse stopped moving. But that horks the other keyboard commands and I'll have to look into that.

On the whole, I'm even more inclined to think it's fruitless because:
a) RE4s up/down aim view does not stay put but self homes.
B) the a/d keys are turn left/right and not strafe.

I'll check PPJoy next.

For the record, here's the code I came up with but messes up other key commands:
#persistent
#singleInstance force
CoordMode, Pixel, Mouse

homeX = 300
homeY = 300

fLeft = false
fRight = false
fUp = false
fDown = false

return

F6::
Settimer, checkmouse, 100

return

checkmouse:
MouseGetPos, curX, curY

If (curX-homeX > 5)
{
    fRight = true
    Send {d Down}
}
else if (fRight)
{
    fRight = false
    Send {d up}
}

If (curX-homeX < -5)
{
    fLeft = true
    Send {a Down}
}
else if (fLeft)
{
    fLeft = false
    Send {a up}
}

If (curY-homeY > 15)
{
    fDown = true
    Send {Down Down}
}
else if (fDown)
{
    fDown = false
    Send {Down up}
}

If (curY-homeY < -15)
{
    fUp = true
    Send {Up Down}
}
else if (fUp)
{
    fUp = false
    Send {Up up}
}

MouseMove, %homeX%, %homeY% , 0
return

F7::Settimer, checkmouse, off

F8::ExitApp


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

But that horks the other keyboard commands and I'll have to look into that.

The only problem I can see is that while the mouse is moving, the script "releases" the modifier keys. This is because:[*:2s27lf3v]it repeatedly sends {a/d/Down/Up Down}, even if the key is already down; and
[*:2s27lf3v]Send causes the modifier keys to be "released."I suggest:
if (fRight != (curX-homeX > 5))
{
    fRight := !fRight
    Send % "{Blind}{d " . (fRight ? "Down}" : "Up}")
}
This compacts the code, doesn't send repeated key-down events, and doesn't interfere with the modifier keys. (The ?: ternary operator requires AHK v1.0.46+.)

When {Blind} is the first item in the string, the program avoids releasing Alt/Control/Shift/Win if they started out in the down position. For example, the hotkey +s::Send {Blind}abc would send ABC rather than abc because the user is holding down the Shift key.

One last thing:
b = false
if (b)
  MsgBox, The string "false" evaluates to true.
Either of the following is acceptable:
b := false  ; in an expression, 'false' = 0
b = 0


whygnat
  • Members
  • 3 posts
  • Last active: Jul 29 2007 07:13 PM
  • Joined: 01 Apr 2007
That's pretty good stuff... thanks! I didn't know ahk went ternary cause I really need to check the new stuff. Next I'll add the left mouse button sending 'e' and rearrange the keys a bit and it should be good.

I'll post what I have but probably not for a week due to a trip. Just wanted to say thanks for the help and quick replies.

Slavka850
  • Guests
  • Last active:
  • Joined: --
is it possible to add in whygnat's version of script one more term?

i mean some thing like this:
GetKeyState(RButton, P)
If (state = 0 and curX-homeX ...)
{
start F6 action
}
else (If state = 1)
{
start F7 sction
}

i tried many ways, but can't do it right...

OceanMachine
  • Members
  • 790 posts
  • Last active: Aug 23 2013 02:10 PM
  • Joined: 15 Oct 2007
Well, that's not quite how you use GetKeyState:
state := GetKeyState("RButton", "P")

If (state = false && curX-homeX ...)

{

   ; start F6 action

}

Else If ( state = true )

{

   ; start F7 sction

}

My code is written for AHK Basic unless otherwise specified. This means it may not work in AHK_L (especially Unicode), due to a few known compatibility issues.

Slavka850
  • Guests
  • Last active:
  • Joined: --
hmmm, second noob question:
how to design "start F6 action" and "start F7 action" so that F6,F7 pressing automatically?
maybe add "Send {F6,F7}"...

plz give me full script, because im really noob in AHK syntax.
thx for answer!