AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Disable Script and Release Key?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Jet Black



Joined: 27 Oct 2009
Posts: 2

PostPosted: Tue Oct 27, 2009 2:21 am    Post subject: Disable Script and Release Key? Reply with quote

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
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 2430

PostPosted: Tue Oct 27, 2009 4:49 am    Post subject: Reply with quote

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

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message
Jet Black



Joined: 27 Oct 2009
Posts: 2

PostPosted: Tue Oct 27, 2009 7:46 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group