Send A key at interval

Post gaming related scripts
User avatar
megnatar
Posts: 92
Joined: 27 Oct 2014, 20:49
Location: The Netherlands
Contact:

Send A key at interval

09 Nov 2015, 05:57

This is a very old script I made ages ago. It sends a key at user specified interval to some window. The key to send must be alphanumeric (aA-zZ/0-9), although I think the functionkeys (F1-F12) can be used to. I used this mainly in mmo games to always have my long buffs on since I always forgot to reactivate them.

The script draws heavy on SetTimer and can be used as oke example on how to use timers/counters and how to write them to a GUI. Maybe I will add a GDI overlay for the key's to send and timers

Features:
-Four key's to specify and send, they can individually be turned on or off.
-The key to send can be variable.
-The interval at which to send them can be variable and are in seconds.
-The program/window to send them to can be variable.
-Writes countdown to next key to trigger in GUI
-Remembers last GUI pos on exit.


Know limitation:
I think it will be wise if I change the SendEvent command to ControlSend so the script will not interfere with userinput.
When you enter two key's in one text field, for the key's you want to send. Then they wont send at all since the send command does not understand
Send, {AA}. I need to make Text input field to allow only one character.

Code: Select all

#NoEnv 
#KeyHistory 0
SetTitleMatchMode, 3
SetBatchLines, -1
ListLines, off 
SetWorkingDir, %A_ScriptDir%

IfExist %A_ScriptName%
{
     IniRead, yPoss, %A_ScriptName%, GuiPoss, yPoss
     sleep, 10
     IniRead, xPoss, %A_ScriptName%, GuiPoss, xPoss
     If (xPoss="")
     {
          xPoss:=A_ScreenWidth/100*50-150                            ;Ore xPoss:=A_ScreenWidth/2-150
     }
     If (yPoss="")
     {
          yPoss:=A_ScreenHeight/100*50-89.5                           ;Ore yPoss:=A_ScreenHeight/2-89.5 
     }
     IniRead, timer4, %A_ScriptName%, UserInput, timer4
     sleep, 10
     IniRead, timer3, %A_ScriptName%, UserInput, timer3
     sleep, 10
     IniRead, timer2, %A_ScriptName%, UserInput, timer2
     sleep, 10
     IniRead, timer1, %A_ScriptName%, UserInput, timer1
     sleep, 10
     IniRead, Key1, %A_ScriptName%, UserInput, Key1
     sleep, 10
     IniRead, Key2, %A_ScriptName%, UserInput, Key2
     sleep, 10
     IniRead, Key3, %A_ScriptName%, UserInput, Key3
     sleep, 10
     IniRead, Key4, %A_ScriptName%, UserInput, Key4
     sleep, 10
     IniRead, OnOff4, %A_ScriptName%, UserInput, OnOff4
     sleep, 10
     IniRead, OnOff2, %A_ScriptName%, UserInput, OnOff2
     sleep, 10
     IniRead, OnOff3, %A_ScriptName%, UserInput, OnOff3
     sleep, 10
     IniRead, OnOff1, %A_ScriptName%, UserInput, OnOff1
     sleep, 10
     IniRead, WinTitle, %A_ScriptName%, UserInput, WinTitle
     sleep, 10
}
Gui, Add, Edit, x21 y11 w20 h20 vKey1, %Key1%
Gui, Add, Edit, x41 y11 w30 h20 vTime1 0x2000, %timer1%
Gui, Add, Checkbox, x80 y11 w50 h20  vOnOff1 Checked%OnOff1%, on/off 
Gui, Add, Edit, x179 y11 w20 h20 vKey2 , %Key2%
Gui, Add, Edit, x199 y11 w30 h20 vTime2 0x2000, %timer2%
Gui, Add, Checkbox, x237 y11 w50 h20  vOnOff2 Checked%OnOff2%, on/off 
Gui, Add, Edit, x21 y51 w20 h20 vKey3, %Key3%
Gui, Add, Edit, x41 y51 w30 h20 vTime3 0x2000, %timer3%
Gui, Add, Checkbox, x80 y51 w50 h20 vOnOff3 Checked%OnOff3%, on/off 
Gui, Add, Edit, x179 y51 w20 h20 vKey4, %Key4%
Gui, Add, Edit, x199 y51 w30 h20 vTime4 0x2000, %timer4% 
Gui, Add, Checkbox, x237 y51 w50 h20  vOnOff4 Checked%OnOff4%, on/off
Gui, Add, Button, x68 y129 w50 h20 , Start
Gui, Add, Button, x128 y129 w50 h20 , Stop
Gui, Add, Button, x187 y129 w50 h20 , Exit
Gui, Add, Button, x14 y90 w32 h28 , Clear
Gui, Add, Text, x120 y85 w64 h15 , WinTitle:
Gui, Add, Edit, x90 y100 w120 h18  vWinTitle, %WinTitle%
Gui, Show, w300 h179  x%xPoss% y%yPoss%, TriggerKey at Interval

WinWait, TriggerKey at Interval
WinGetPos, , , wWide, hTall, TriggerKey at Interval
wWide:=wWide/2
hTall:=hTall/2
xPoss:=A_ScreenWidth/100*50
xPoss:=xPoss-wWide
yPoss:=A_ScreenHeight/100*50
yPoss:=yPoss-hTall
Return

ButtonClear: 
Gui, submit, nohide 
xPoss:=A_ScreenWidth/100*50
xPoss:=xPoss-wWide
yPoss:=A_ScreenHeight/100*50
yPoss:=yPoss-hTall
xPoss1:=xPoss
yPoss1:=yPoss
timer4=
timer2=
timer3=
timer1=
OnOff4=0
OnOff2=0
OnOff3=0
OnOff1=0
WinTitle=
Key1=1
Key2=2
Key3=A
Key4=B
GuiControl, Text, WinTitle, %WinTitle%
GuiControl, Text, Key1, %Key1%
GuiControl, Text, Key2, %Key2%
GuiControl, Text, Key3, %Key3%
GuiControl, Text, Key4, %Key4%
GuiControl, Text, Time1, %timer1%
GuiControl, Text, Time2, %timer2%
GuiControl, Text, Time3, %timer3%
GuiControl, Text, Time4, %timer4%
Gui, Show, w300 h179  x%xPoss% y%yPoss%, TriggerKey at Interval
return

!q::                ;Alt+Q=Quit/Exit
ButtonExit:
GuiClose: 
Gui, submit
Key1=%Key1%
Key2=%Key2%
Key3=%Key3%
Key4=%Key4%
timer4=%Time4%          
Timer2=%Time2%
Timer3=%Time3%
timer1=%Time1%
Stop1:=0                 
Stop2:=0 
Stop3:=0 
Stop4:=0

If (xPoss1 <> xPoss || yPoss1 <> yPoss ) 
{
     WinGetPos, xPoss, yPoss
}
IniWrite, %xPoss%, %A_ScriptName%, GuiPoss, xPoss
sleep, 10
IniWrite, %yPoss%, %A_ScriptName%, GuiPoss, yPoss
sleep, 10
IniWrite, %timer4%, %A_ScriptName%, UserInput, timer4
sleep, 10
IniWrite, %timer2%, %A_ScriptName%, UserInput, timer2
sleep, 10
IniWrite, %timer3%, %A_ScriptName%, UserInput, timer3
sleep, 10
IniWrite, %timer1%, %A_ScriptName%, UserInput, timer1
sleep, 10
IniWrite, %Key1%, %A_ScriptName%, UserInput, Key1
sleep, 10
IniWrite, %Key2%, %A_ScriptName%, UserInput, Key2
sleep, 10
IniWrite, %Key3%, %A_ScriptName%, UserInput, Key3
sleep, 10
IniWrite, %Key4%, %A_ScriptName%, UserInput, Key4
sleep, 10
IniWrite, %OnOff4%, %A_ScriptName%, UserInput, OnOff4
sleep, 10
IniWrite, %OnOff2%, %A_ScriptName%, UserInput, OnOff2
sleep, 10
IniWrite, %OnOff3%, %A_ScriptName%, UserInput, OnOff3
sleep, 10
IniWrite, %OnOff1%, %A_ScriptName%, UserInput, OnOff1
sleep, 10
IniWrite, %WinTitle%, %A_ScriptName%, UserInput, WinTitle
sleep, 10
ExitApp

!p::                ;Alt+P=Stop/Pause
ButtonStop:
SetTimer, Show1, Off
SetTimer, Show2, Off 
SetTimer, Show3, Off 
SetTimer, Show4, Off
GuiControl, Text, Time1, %timer1%
GuiControl, Text, Time2, %timer2%
GuiControl, Text, Time3, %timer3%
GuiControl, Text, Time4, %timer4%
Return

!s::                ;Alt+S=Start
ButtonStart:
WinActivate, %WinTitle% 
Gui, submit, nohide        
Key1=%Key1%
Key2=%Key2%
Key3=%Key3%
Key4=%Key4%
timer4=%Time4%          
Timer2=%Time2%
Timer3=%Time3%
timer1=%Time1%
Time1:=Time1*1000      
Time2:=Time2*1000
Time3:=Time3*1000
Time4:=Time4*1000
;--------------------------Timer1--------------------------
If (OnOff1=True){
     SetTimer, Show1, 1000                
}Else{       
    SetTimer, Show1, Off
}
;--------------------------Timer2--------------------------
If (onoff2=True){
     SetTimer, Show2, 1000
}Else{
    SetTimer, Show2, Off
}
;--------------------------Timer3--------------------------
If (onoff3=True){
     SetTimer, Show3, 1000
}Else{
    SetTimer, Show3, Off
}
;--------------------------Timer4--------------------------
If (OnOff4=True){
     SetTimer, Show4, 1000
}Else{
    SetTimer, Show4, Off
}
Return
;--------------------------GuiUpdateEvent1--------------------------
Show1:
Stop1+=1              
Counter1:=timer1-Stop1 
GuiControl, Text, Time1, %Counter1% 
If Stop1=%timer1%                
{
     Stop1=0
     SendEvent, {%Key1%} 
}
return
;--------------------------GuiUpdateEvent2--------------------------
Show2:
Stop2++                                     ;Ore use the ++ operator
Counter2:=Timer2-Stop2 
GuiControl, Text, Time2, %Counter2%
If Stop2=%Timer2% 
{
     Stop2=0
     SendEvent, {%Key2%}
}
return
;--------------------------GuiUpdateEvent3--------------------------
Show3:
Stop3+=1 
Counter3:=Timer3-Stop3
GuiControl, Text, Time3, %Counter3%
If Stop3=%Timer3% 
{
     Stop3=0
     SendEvent, {%Key3%}
}
return
;--------------------------GuiUpdateEvent4--------------------------
Show4:
Stop4+=1 
Counter4:=timer4-Stop4
GuiControl, Text, Time4, %Counter4% 
If Stop4=%timer4% 
{
     Stop4=0
     SendEvent, {%Key4%}
}
return
;--------------------------Script Variables--------------------------
;--------------------------DO NOT DELETE--------------------------
/*
[GuiPoss]
xPoss=
yPoss=
[UserInput]
timer4=
timer2=
timer3=
timer1=
OnOff4:=0
OnOff2:=0
OnOff3:=0
OnOff1:=0
WinTitle=
Key1=1
Key2=2
Key3=A
Key4=B
OnOff4=0
OnOff2=0
OnOff3=0
OnOff1=0
*/
Everything we call real is made of things that cannot be regarded as real!
N.Bohr.

Really, that probability is true!

Return to “Gaming Scripts (v1)”

Who is online

Users browsing this forum: No registered users and 24 guests