Hi - joined the forum for a bit of help. I have absolutely no knowledge (basically none) on how to code for AutoHotkey, but managed to snag some code written for FarCry2 months ago and have altered it to work with any game...
Basically, I can't play with Iron Sights/Zoom that doesn't toggle, so this toggles it... it takes the 'i' key and replaces it with 'v' and enables a toggle. It works very well... only problem is when I want to chat, my i's become v's.
Built into the code is a way to disable it 'q', but it only disables the toggle function, doesn't release the letter 'i' for use.
Does anyone know if it's possible to add the release function to this code so that I can toggle it on/off easily and chat with people without throwing up v's everywhere?
Code:
;#######################################################
#NoEnv
SendMode Input
SetTitleMatchMode, RegEx
;/* The actual key presses that are sent to the game to manipulate.
; * We should map these keys to crouch and ironsights in the game's control
; * configs for our bindings to actually work.
; * You can change these (the characters inside quotes) if you wish
; * to use other keys/buttons for the commands
; */
SightSwitch := "q" ;// Turns on/off sight toggle functionality
SightKey := "v" ;// Key bound in game for iron Sights
NewSightKey := "i" ;// Key we will use for iron sights
;/* Variables to enable/disable our hotkey toggles */
sightToggleEnabled := 1
;/* Variables to keep track of our toggle states, both for crouching, anda
; * also iron sights */
sighting := 0 ;// we are currently sighting down the gun
;Define Hotkeys so that they are only Active when running FarCry2 application
;=======================================================
;=======================================================
;Hotkey, IfWinActive, ahk_class Nomad* ;// Only active when class matches Nomad
;// The key/button presses that will trigger our AHK script
Hotkey, %SightSwitch% , SightEnableInput
Hotkey, *%NewSightKey%, SightKeyInput
return
;/* Toggle the Sight hotkeys on/off. When "on" hotkey replacement happens, when off
; * the keys/buttons are sent to the game unaltered
; */
SightEnableInput:
if (sightToggleEnabled)
{
sightToggleEnabled := 0 ;// Turn off crouch toggle hotkey
sighting := 0
}
else
{
sightToggleEnabled := 1 ;// Turn on crouch toggle hotkey
}
return
;/* Implement sight toggle functionality. Rather than having to hold the sight
; * button down, you press once to look down the iron sights, and press again to
; * to stop sighting. Care must be taken to maintain the current sighted state
; * (ie. effectively whether the "Button" is being held down or not) */
SightKeyInput:
if (sightToggleEnabled && sighting) ; // We are using sights and should stop
{
sighting := 0
Send {%SightKey% up}
}
else if (sightToggleEnabled) ;// sighting = 0, ie not sighting
{
keywait %SightKey% ;// Wait for button-up event to reach game, since it can't be supressed
sighting := 1
Send {%SightKey% down}
}
else ;// Sight toggle disabled. We still need to keep track of state
{
;/* Send the keys as is, let the game handled it */
sighting := 1
send {%SightKey% down} ;// User already pressed key, so send to game
keywait %SightKey% ;// User let go
sighting := 0
send {%SightKey% up} ;// Send the "let go of key" to the game
}
return