Jump to content


Multiple Key script need help


  • Please log in to reply
6 replies to this topic

#1 Blien

Blien
  • Guests

Posted 13 July 2012 - 12:37 AM

Below is my script, which for a game hotkey, so I blind F1-F4 for different function, F1 = 1, F2 = 2, F3 = 3, F4 = 123 while F1 & F2 together = 12 and so on, overall the script itself works fine except while lets say when I press F1 & F2 together it does 12 to me, but when I release F1 I was hoping it will keep doing F2 for me but the script I do will completely stop once i release one of the key, so in that case I will have to release F2 aswell and repress F2 again if I need to run F2 again, can anyone please help me mod my script so if I remove one of the key I will keep running for the rest of the function??

Thanks
Blien


#MaxHotkeysPerInterval 500
#persistent



F1::
F2::
F3::
F4::

If ( GetKeyState("F1") && GetKeyState("F2") && GetKeyState("F3"))
    Send 123

Else If ( GetKeyState("F1") && GetKeyState("F2"))
	{ ; 
		Random, time, 50, 100 
		Send 12
		Sleep, %time%
	}
Else If ( GetKeyState("F3") && GetKeyState("F2"))
	{ ; 
		Random, time, 100, 200 
		Send 23
		Sleep, %time%
		;break 
	}

Else If ( GetKeyState("F1") && GetKeyState("F3"))
	{ ; 
		Random, time, 150, 200
		Send 13
		Sleep, %time%
	}

Else If ( GetKeyState("F1"))
	{ ; 
		Random, time, 100, 200 
		Send 1
		Sleep, %time%
	}

Else If ( GetKeyState("F3"))
	{ ; 
		Random, time, 300, 500 
		Send 3
		Sleep, %time%
	}
Else If ( GetKeyState("F2"))
	{ ; 
		Random, time, 100, 200 
		Send 2
		Sleep, %time%
	}
Else If ( GetKeyState("F4"))
	{ ; 
		Random, time, 100, 200 
		Send 123
		Sleep, %time%
	}

return


#2 dylan904

dylan904
  • Members
  • 706 posts

Posted 13 July 2012 - 01:29 AM

I would use the built-in variable A_ThisHotkey, but it's hard, because i wouldn't use the setup you have, considering it uses the same hotkey with different configurations. I wouldn't use hotkeys where it is a hotkey as well as it plus other buttons combined is another. You need to figure out which direction you want to go with that, then hopefully I can be of some more help.

#3 girlgamer

girlgamer
  • Moderators
  • 2039 posts

Posted 13 July 2012 - 02:48 AM

Try this and see if it works for you... Use Alt-t to turn the scanner on and off. Use Esc to stop the script
#NoEnv
#SingleInstance, Force
#Persistent
#MaxThreadsPerHotkey 2
SetTitleMatchMode, 2
SetBatchLines, -1
SetKeyDelay, 50,50
DetectHiddenWindows, On
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
;SendMode, Event

ktrun = 0
Return	;<-- force logical end of autoexecute section

;------------------------------------------------
;timer on and off
!t::	;<-- turn on fkey timer
	ktrun := (!ktrun)
	If (ktrun)
		Gosub fkeyT
	Return

;------------------------------------------------
; fkeytimer routine
fkeyT:
If (ktrun)
{	fngetKeyPressed()
	SetTimer FKeyT, -100 ;<-- one shot timer to prevent race conditions
}
Return

;------------------------------------------------
; function to check fkeys state
fnGetKeyPressed()
{	k1 =
	k2 =
	k3 =
		
	If (GetKeyState("F4","P"))
		Send, 123
	Else
	{
		If (GetKeyState("F1","P"))	
			k1 = 1
		If (GetKeyState("F2","P"))
			k2 = 2
		If (GetKeyState("F3","P"))	
			k3 = 3
		Send, %k1%%k2%%k3%
	}	
	random, t,50,200
	Sleep, %t%
}

;------------------------------------------------
; stop script
~Esc::ExitApp



#4 Blien

Blien
  • Guests

Posted 13 July 2012 - 04:26 AM

I will try this later tonight and let you know if it works, thanks

Try this and see if it works for you... Use Alt-t to turn the scanner on and off. Use Esc to stop the script

#NoEnv
#SingleInstance, Force
#Persistent
#MaxThreadsPerHotkey 2
SetTitleMatchMode, 2
SetBatchLines, -1
SetKeyDelay, 50,50
DetectHiddenWindows, On
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
;SendMode, Event

ktrun = 0
Return	;<-- force logical end of autoexecute section

;------------------------------------------------
;timer on and off
!t::	;<-- turn on fkey timer
	ktrun := (!ktrun)
	If (ktrun)
		Gosub fkeyT
	Return

;------------------------------------------------
; fkeytimer routine
fkeyT:
If (ktrun)
{	fngetKeyPressed()
	SetTimer FKeyT, -100 ;<-- one shot timer to prevent race conditions
}
Return

;------------------------------------------------
; function to check fkeys state
fnGetKeyPressed()
{	k1 =
	k2 =
	k3 =
		
	If (GetKeyState("F4","P"))
		Send, 123
	Else
	{
		If (GetKeyState("F1","P"))	
			k1 = 1
		If (GetKeyState("F2","P"))
			k2 = 2
		If (GetKeyState("F3","P"))	
			k3 = 3
		Send, %k1%%k2%%k3%
	}	
	random, t,50,200
	Sleep, %t%
}

;------------------------------------------------
; stop script
~Esc::ExitApp



#5 MasterFocus

MasterFocus
  • Moderators
  • 4132 posts

Posted 13 July 2012 - 05:15 AM

Here are my attemps, also using only one timer. Both tested.

Toggleable version:
#NoEnv
#SingleInstance, Force
#Persistent
#MaxThreadsPerHotkey 2
SetTitleMatchMode, 2
SetBatchLines, -1
SetKeyDelay, 50,50
DetectHiddenWindows, On
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen

Loop, [color=#BF40FF]3[/color] {
    Toogle%A_Index% := 0
    Hotkey, [color=#BF0000]F[/color]%A_Index%, ToggleLabel
}

SetTimer, SpamKeyRoutine, 50

Return

;------------------------------------------------

ToggleLabel:
    Key := SubStr(A_ThisHotkey,0)
    Toggle%Key% := !Toggle%Key% + 1
Return

;------------------------------------------------

SpamKeyRoutine:
    [color=#FF0000]TEXT := ""[/color]
    Loop, [color=#BF40FF]3[/color] {
        [color=#FF0000]TEXT .= "`t" Toggle%A_Index%[/color]
        If (Toggle%A_Index% >= 1)
            Toggle%A_Index%--
        If (Toggle%A_Index% == 1) {
            [color=#FF8000]Send, %A_Index%[/color]
            Random, Time, 1, 6 [color=#008000]; 1*50ms ~ 6*50ms , because the routine runs every 50ms[/color]
            Toggle%A_Index% := Time+1
        }
    }
        [color=#FF0000]TOOLTIP, % SUBSTR(TEXT,2)[/color]
Return

;------------------------------------------------

~Esc::ExitApp

Version which requires holding F1~F3:
#NoEnv
#SingleInstance, Force
#Persistent
#MaxThreadsPerHotkey 2
SetTitleMatchMode, 2
SetBatchLines, -1
SetKeyDelay, 50,50
DetectHiddenWindows, On
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen

Loop, [color=#FF2222]3[/color]
    Key%A_Index% := 0

SetTimer, SpamKeyRoutine, 50

Return

;------------------------------------------------

SpamKeyRoutine:
    Loop, [color=#FF2222]3[/color] {
        If (Key%A_Index% > 0)
            Key%A_Index%--
        Else If GetKeyState(  "F" A_Index  ,  "P"  ) {
            [color=#FF8000]Send, %A_Index%[/color]
            Random, Time, 1, 6 [color=#008000]; 1*50ms ~ 6*50ms , because the routine runs every 50ms[/color]
            Key%A_Index% := Time
        }
    }
Return

;------------------------------------------------

~Esc::ExitApp


#6 Blien

Blien
  • Guests

Posted 13 July 2012 - 11:32 AM

First of all, thanks to girlgamer & MasterFocus, I've tried all 3 and end up using girlgamer atm, the 2nd version of Masterfocus are pretty much the same stuff but missing F4 for 123 :p, but anyway, both script do have some odd issue which from what i see the script should work while all F1 F2 and F3 key are pressed, but none of it actually work that way, maximum key can press together will be 2 for some odd reason, is it me having issue or are there limitation on the program itself?? Anyway, thanks both again =)

#7 dylan904

dylan904
  • Members
  • 706 posts

Posted 14 July 2012 - 12:22 AM

I'm thinking it's an issue with your physical keyboard maybe?