1) #IfWinActive not working 2) Mouse move funky

Ask gaming related questions (AHK v1.1 and older)
User avatar
chazcon
Posts: 18
Joined: 03 Aug 2015, 23:12

1) #IfWinActive not working 2) Mouse move funky

24 Dec 2015, 21:37

I have this script for Far Cry 3 and I have 2 problems.

I'm running the game in Borderless Windowed mode.

1) #IfWinActive is not working, in this way - the script works in the game, but it also continues to work when in a different window, like Notepad++ or a browser. I've tried different WinTitles like the full title, the id, and as you see here a partial which should work.

2) Pressing A or D is intended to move the mouse cursor in the X axis only and it works fine at first. I also can move the cursor around with the mouse. After several minutes the script will move to a very different Y axis, either way up or down, but the Y axis should never change. Very odd, do you think this is some type of anti-mod feature of the game?

Code: Select all

#NoEnv  						
#SingleInstance Force 			
SendMode Input  				
SetWorkingDir %A_ScriptDir%  	

SetTitleMatchMode 2
#IfWinActive Cry
;0x304b4
;Nomad
;Far Cry® 3

SetNumlockState, AlwaysOn		; sets NumLock to Always On for using Numpad keys

LAlt::N							; maps LAlt to N for strafing (map Strafe Left to N in game)
RAlt::M							; maps RAlt to M for strafing (map Strafe Right to M in game)

LWin::LAlt						; maps LWin to LAlt in case I hit that mother while strafing
RWin::RAlt						; maps RWin to RAlt in case I hit that mother while strafing
		
!Tab::return					; removes Alt-Tab so I can strafe without alt-tabbing
!Enter::return					; removes Alt-Enter so I don't toggle Fullscreen/Windowed mode
		
LShift & RShift::AltTab 		; requires pressing both LShift & RShift to alt-tab

~a::
	MouseMove -5,0,2,R
return

~d::
	MouseMove 5,0,2,R
return
FOR THE VITAE!
User avatar
chazcon
Posts: 18
Joined: 03 Aug 2015, 23:12

Re: 1) #IfWinActive not working 2) Mouse move funky

24 Dec 2015, 22:38

Re: # 2) Above, I think the game randomizes mouse coords, it changes the x and y axis every 30s or so.

I just hate mouse turning, and although I need it to aim and shoot, I want to turn using the keyboard (not strafe).
FOR THE VITAE!
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: 1) #IfWinActive not working 2) Mouse move funky

25 Dec 2015, 04:39

#1: I'd think it's unlikely Notepad or a browser would match 'Far Cry® 3' in the title, but how about you try the executable name: ahk_exe farcry.exe (obviously put the right file name there).

#2: MouseMove actually sets the cursor location. Once you reach the edge of the screen or the game resets the location it get wonky. For a different game I used the following which inputs mouse movement (cursor will still move but it'll continue to work near the desktop border or during cursor repositioning).

Code: Select all

F3:: ;Move the cursor far right and slightly down
	VarSetCapacity( MouseInput, 28, 0 )
	NumPut( 0x0020, MouseInput, 4, "Int" ) ; dx=0x20
	NumPut( 0x0001, MouseInput, 8, "Int" ) ; dy=1
	NumPut( 0x0001, MouseInput, 16, "UInt" ) ; MOUSEEVENTF_MOVE = 0x0001

	loop
	{
		DllCall("SendInput", "UInt", 1, "UInt", &MouseInput, "Int", 28 )
		Sleep,10
		If !Getkeystate(A_ThisHotkey, "P")
			Break
	}
Return
You can set two variables for left and right and input those in the DllCall without settings their contents repeatedly.
User avatar
chazcon
Posts: 18
Joined: 03 Aug 2015, 23:12

Re: 1) #IfWinActive not working 2) Mouse move funky

25 Dec 2015, 12:27

Nex, Good info, let me try that.
FOR THE VITAE!
User avatar
chazcon
Posts: 18
Joined: 03 Aug 2015, 23:12

Re: 1) #IfWinActive not working 2) Mouse move funky

25 Dec 2015, 16:32

Here is my current code. The original problems are still present:

1) Changed to IfWinActive from #IfWinActive, oddly SOME commands inside the brackets are still enabled when I'm not in the game window if the game is running, i.e game is running but I'm alt-tabbed to my browq
FOR THE VITAE!
User avatar
chazcon
Posts: 18
Joined: 03 Aug 2015, 23:12

Re: 1) #IfWinActive not working 2) Mouse move funky

25 Dec 2015, 16:39

Here is my current code. The original problems are still present:

1) Changed to IfWinActive from #IfWinActive, the script does not recognize when I'm in the game or in another app, all commands work regardless of app in focus which is bad. Even if the game id not running the commands fire. Is there a problem in my code or is this a Windows 10 thing maybe?

2) I'm assuming this game Gar Cry 3 has some sort of anti-aimbot code. I'm trying to just look left and right using keys A and D (not strafe) but of course I'm sending mouse cursor inputs which is triggering the anti-cheat after 10-20 uses of those keys. What it's doing is randomizing the mouse coords, in other words the Y axis will change from 0 at the top to 1120 at the bottom, to something like 483 at the top, 960 at the bottom, same for X axis. Very effective and it really sucks lol. I'm trying to be able to look left and right in increments, the same thing the mouse would do if you move it left and right, without any change to the Y axis. Is there another input method or a way to control the mouse maybe, so the lft/right inputs would come from the mouse and 'look normal' to the game?

Code: Select all

#NoEnv	
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
SetNumlockState, AlwaysOn

;SendMode Input|Play|Event|InputThenPlay	
SendMode Input

;CoordMode, ToolTip|Pixel|Mouse|Caret|Menu [, Screen|Window|Client]
CoordMode Mouse Window

; Constants
MouseMoveDistance = 3
MouseMoveSpeed = 50			; 0-100

SetTitleMatchMode 2
IfWinActive ahk_exe farcry3_d3d11.exe
{

LAlt::N						; maps LAlt to N and RAlt to M for strafing
RAlt::M

LWin::LAlt					; maps LWin to LAlt and RWin to RAlt in case I hit that while strafing
RWin::RAlt
		
LShift & RShift::AltTab		; requires pressing both LShift & RShift to alt-tab

!Tab::return				; removes Alt-Tab so I can strafe without alt-tabbing
!Enter::return				; removes Alt-Enter so I don't toggle Fullscreen/Windowed mode

~w::						; when I press Move Forward, makes me get up from crouch and sprint
	Send, q					
	Send, {Tab}	
	KeyWait w				; when I stop moving, drops me into a crouch
	Send, q	
return

/*
~a::						; METHOD 01 - allows me to keyboard turn (mouse turn still active)
	MouseMove -4,0,MouseMoveSpeed,R
return
~d::
	MouseMove 4,0,MouseMoveSpeed,R
return
*/

~a::						; METHOD 02 - allows me to keyboard turn (mouse turn still active)
	MouseGetPos xpos, ypos
	xpos -= MouseMoveDistance
	If (ypos <=500) or (ypos >= 1000) ; crude way to get around the game's randomization of mouse coords
	{
		ypos = 800
	}
	MouseMove xpos,ypos,MouseMoveSpeed
return
~d::
	MouseGetPos xpos, ypos
	xpos += MouseMoveDistance
	If (ypos <=500) or (ypos >= 1000) ; crude way to get around the game's randomization of mouse coords
	{
		ypos = 800
	}
	MouseMove xpos,ypos,MouseMoveSpeed
return
}
FOR THE VITAE!
User avatar
chazcon
Posts: 18
Joined: 03 Aug 2015, 23:12

Re: 1) #IfWinActive not working 2) Mouse move funky

25 Dec 2015, 16:41

Hah that first partial post triggered a command, I had to exit the script. Exactly what I'm talking about.
FOR THE VITAE!
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: 1) #IfWinActive not working 2) Mouse move funky

25 Dec 2015, 17:33

With your code, you need #IfWinActive instead of IfWinActive.

Unfortunately, I have no idea for the rest of the issues you are experiencing.
User avatar
chazcon
Posts: 18
Joined: 03 Aug 2015, 23:12

Re: 1) #IfWinActive not working 2) Mouse move funky

25 Dec 2015, 22:36

Solved for now. I cannot resolve issue #2 because of the games anti-cheat software, no workaround.

Thanks for the hekp on issue # 1. Final code, cleaned up a bit:

Code: Select all

#NoEnv	
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

#IfWinActive ahk_exe farcry3_d3d11.exe

; Constants
MouseMoveDistance = 3
MouseMoveSpeed = 50			; 0-100

LShift::V					; maps LShift to N and LAlt to M for strafing
LAlt::B

LWin::LAlt					; maps LWin to LAlt and RWin to RAlt in case I hit that while strafing
RWin::RAlt
		
RAlt & RShift::AltTab		; requires pressing both LShift & RShift to alt-tab

!Tab::return				; removes Alt-Tab so I can strafe without alt-tabbing
!Enter::return				; removes Alt-Enter so I don't toggle Fullscreen/Windowed mode

~w::						; when I press Move Forward, makes me get up from crouch and sprint
	Send, q					
	Send, {Tab}	
	KeyWait w				; when I stop moving, drops me into a crouch
	Send, q	
return

/*							; WELL this won't work because of PunkBuster
~a::						; allows me to keyboard turn (mouse turn still active)
	MouseGetPos xpos, ypos
	xpos -= MouseMoveDistance
	MouseMove xpos,ypos,MouseMoveSpeed
return

~d::
	MouseGetPos xpos, ypos
	xpos += MouseMoveDistance
	MouseMove xpos,ypos,MouseMoveSpeed
return
*/
FOR THE VITAE!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 137 guests