AutoHotkey Community

It is currently May 26th, 2012, 10:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: October 27th, 2009, 3:21 am 
Offline

Joined: October 27th, 2009, 3:15 am
Posts: 2
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 5:49 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Try this just to see if it works, q should toggle the value of variable 'toggle' for the purposes of the 'i' key:

Code:
q::toggle=!toggle

i::
if toggle
  Send v
else
  Send i
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 27th, 2009, 8:46 am 
Offline

Joined: October 27th, 2009, 3:15 am
Posts: 2
Thanks. I gave it a try at the bottom of the script, and then moved it around because it didn't seem to be working. For some reason when that set is in there, it ignores the rest of the script. Even trying to toggle it on with q isn't turning it on.

I think I see where you're going though - maybe? To have q both enable/disable the toggle and have it its own toggle that when it's on, i returns i and when it's off, i returns v?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: AndyJenk, JSLover, Leef_me, patgenn123, rbrtryn, Yahoo [Bot] and 73 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group