Jackthehat wrote:
Opps sorry BoBo
will try and give it a shot is there a way to debug code with out running BF2 could I change BF2.exe and put notepad.exe or is there a nice tool to capture and see what is being pressed eg if it pressed Shift and Crtl you would not see this in notepad
I replied to your PM, thanks for expressing an interest in the idea. The original code I posted might have been missing some variables or such when I copied and pasted so I went back to my original and extracted all the QuickSwitch related pieces and tried them out in a Standalone script. Tested it in Notepad first and then fired up BF2 in singleplayer and the QuickSwitch is working ok so hope you find the below useful.
Code:
;GameName = notepad.exe ; use when testing in notepad
GameName = bf2.exe ; Set exe name here
KeySleep1 = 100 ; Ideal Sleep time for BF2 commands (check?, SetKeyDelay influence?)
v_InTextChatOn := False ; Used for pausing running of Script
v_LastUsedWeapon = 3 ; Initialise as Primary Weapon 3
v_LastStoredWeapon = 3 ; Initialise as Primary Weapon 3
#Persistent
#NoEnv ; prevents empty variables from being looked up
#SingleInstance force
#InstallKeybdHook
#InstallMouseHook
SetKeyDelay, 75, 75 ; NB: Once "WeaponSelect()" added this was needed!!
SetTimer, KeepRunning ; Only run this script when {BF2.exe} is running in the foreground
Return
;;;; Timer related ;;;;
KeepRunning:
; Get the process name of the active window (i.e. Notepad.exe)
; Only run this script when Battlefield 2 {BF2.exe} is running in the foreground.
WinGet, szProcessName, ProcessName, A
If szProcessName = %GameName% ; Determine if window Active, enable hotkeys
{
; If running check to determine whether in chat mode.
If (v_InTextChatOn == False) ; Text chat isn't active so allow hotkeys
{
Suspend, off
}
Else if (v_InTextChatOn == True) ; Text chat is active so disable hotkeys
{
Suspend, on
}
}
Else ; Else window inactive, disable hotkeys
{
Suspend, on
}
Return
; --------------------
; Quickswitch related.
$1::WeaponSelect(1)
$2::WeaponSelect(2)
$3::WeaponSelect(3)
$4::WeaponSelect(4)
$5::WeaponSelect(5)
$6::WeaponSelect(6)
$f::Goto, QuickSwitch
QuickSwitch:
KeyPress(ByVar v_LastUsedWeapon) ; QuickSwitch: "v_LastUsedWeapon" is declared globally and stored by "QuickSwitchVar()" function
return
QuickSwitchVar(v_ChosenWeapon)
; 1.Edit Store previous weapon, 2. Placeholder variable for current weapon so next use of function can determine previous weapon
{
Global v_LastUsedWeapon
Global v_LastStoredWeapon
v_LastUsedWeapon = %v_LastStoredWeapon% ; QuickSwitch: Previous run stored source for this variable. Used to record last used Weapon and used in QuickSwitch usage
v_LastStoredWeapon = %v_ChosenWeapon% ; QuickSwitch: Stored so the following call of function can determine Previous Weapon
}
WeaponSelect(v_ChosenWeapon)
; Select weapon 1 - 6 %v_ChosenWeapon%
{
If( v_ChosenWeapon > 0 and v_ChosenWeapon < 7)
{
Global v_LastStoredWeapon ; QuickSwitch: Declare this to to access it and determine previous weapon
If( v_ChosenWeapon <> v_LastStoredWeapon) ; QuickSwitch: If current weapon wasn't pressed last time then ...
QuickSwitchVar(ByRef v_ChosenWeapon) ; ... update variables for weapon history.
Send, {%v_ChosenWeapon% Down}
Sleep %KeySleep1%
Send, {%v_ChosenWeapon% Up}
}
Else
Send, @huh????%v_ChosenWeapon%
Sleep 50
}
KeyPress(v_KeyName)
{
Send, {%v_KeyName% Down}
Sleep %KeySleep1%
Send, {%v_KeyName% Up}
If( v_KeyName > 0 and v_KeyName < 7) ; QuickSwitch: Check if weapon, between 1-8, should it be 1-6 as NightVision and gas Mask not really need in the switch?
; NB: Above 'If' only needed if Quickswitch desired.
{
v_ChosenWeapon = %v_KeyName%
QuickSwitchVar(ByRef v_ChosenWeapon)
}
}
; --------------------
When I originally thought of I thought it would be quiet simple but of course as I delved in a little deeper it became a little more complex, after some trial and error in Notepad the code evolved and the above appears to work fine. Someone a little more expereinced with coding might be able to simplify it further. Anyway hope someone finds it useful.