repeat the entire AHK code - autohotkey

XButton2::
if( not GetKeyState("t","P") )
Send {t down}
While GetKeyState("XButton2","P"){
Sendinput, f
sleep, 30
}
return
XButton2 Up::Send {t up}
So what this code does is when I press and hold XButton2 it holds "t" down and while "t" is down it spams "f". What im trying to do is to repeat this action of holding "t" down and spaming "f" every 100ms, not sure what to do next

Related

Why are a and d not getting pressed the same amount?

I need a macro to press "a" then "d" shortly after and i need them to be pressed the same amount but it isn't working, how can i fix this?
Loop {
Send {s down}
Click, right
Sleep, 1
Send {d up}
Send {a down}
Click, R
Send {s down}
Click, right
Sleep, 1
Send {a up}
Send {d down}
Click, R
}
Can you clarify what the hole script should do?
If you just want to press "a" and afterwards "d", don't use the "up" and "down" parameters.
1::
Loop{
send {a}
send {d}
}
If you need the buttons to be pressed an precise amount of time, work with some sleeps.
1::
Loop{
send {a down}
sleep x
send {a up}
send {d down}
sleep x
send {d up}
}

Disable/Block a Key with another Key while its pressed and held down

So in this game im moving my charachter with the WASD keys, but if i hold down the A and D key at the same time,
the game register that as a forward movement (W key |) so the charachter starts to move forward instead of the strafe actions (Left) \ (right) /.
So i need a code which is prevents the A and D key simultaneous pressing.
CHECK THIS GIF, SO U CAN SEE WHAT I MEAN!
I want A and D override each other (Im not using the W key), because if i hit both A and D at the same time my character moves forward, not like this \ /
and i want to avoid the forward movements.
I want insantly changed fast Left \ and Right / strafing only.
Here is the code what i got so far:
~a::
If (GetKeyState("d", "p"))
{
Send {d up}
d = 0
}
Return
~d::
If (GetKeyState("a", "p"))
{
Send {a up}
a = 0
}
Return
a up::
If (d)
{
Send {d down}
d = 0
}
Return
d up::
If (a)
{
Send {a down}
a = 0
}
Return
Basicly this code almost working.
The problem is if i don't change the numbers i can't change directions continuously i need to let go the keys. It stops after 1 direction change. If i change the numbers its working, but after a few direction change its getting toggled either left or right. Even if i let it go its moving left or right....
Any ideas? thx
This should work. Try it and let me know.
$*a::
$*d::
SendInput, {a Up}{d Up}
StringReplace, hk, A_ThisHotkey, % "$*"
SendInput, {%hk% Down}
KeyWait, % hk
Send, {a Up}{d Up}
return
EDIT: You can play around with the code below. Maybe it will help you out
#SingleInstance, force
#Persistent
#NoEnv
#MaxThreadsPerHotkey, 1
~a & d::
~d & a::
Send, {a up}
key := "d"
SetTimer, pressdown, 10
return
~d::key := "d"
~a::key := "a"
~a up::key := "d"
~d up::key := "a"
pressdown:
if GetKeyState(key, "p")
{
SendInput, {%key% down}
SetTimer, pressdown, 30
}
else {
SetTimer, pressdown, Off
SendInput, {%key% up}
}
return
This script cannot allow A, or D to be simultaneously pressed.

AHK: GetKeyState, can't send 2 commands

Basically what I want to do is: While I hold down the "a"-key the script automatically holds and releases the "a"-key over and over. It also has to press or hold/release the "h"-key. It causes me problems when I try to add the "h"-key (it spams the "h"-key whenever I activate the script instead of waiting for an "a"-press).
#Persistent
SetTimer, Clicking
F2::ExitApp
Clicking:
a::
if (GetKeyState("a", "P"))
Send {a down}
Send {h down}
Sleep 100
Send {h up}
Send {a up}
Sleep 475
Return
a up:: Send {a up}
Any help would be greatly appreciated! :-)
You need braces around your if block:
if (GetKeyState("a", "P"))
{
Send {a down}
Send {h down}
...
}

Toggle Shift for Single Keypress

I am trying to turn my shift key into a CapsLock of sorts. The goal being that, when Shift is pressed, it shifts the next key to be pressed (eliminating the need to hold down the shift key), similar to the function of StickyKeys but only for the Shift key. I am able to toggle the Shift key using:
LShift:: Send % "{Blind}{LShift " . ((lshift:=!lshift) ? "Down}" : "Up}")
But that requires me to press Shift again, basically turning it into a CapsLock. How can I have this action only last for one keypress?
This should do:
$LShift::
SendInput, {LShift Down}
KeyWait, LShift
SendInput, {LShift Down}
Input, Key, L1 V
SendInput, {LShift Up}
Return
edit:
$*LShift::
SendInput, {LShift Down}
Input, Key, L1 M V
If GetKeyState("LShift", "P")
KeyWait, LShift
SendInput, {LShift Up}
Return

Autohotkey: Can't figure out why this is pushing Shift along with the rest of the code

I am trying to make a macro that will repeat hitting O and M as long as i have my side mouse button held down, but all of a sudden now it is also hitting shift. Any idea why or how to fix it?
delaybetweenfkeys:=0
fkeydowndelay:=5
XButton1::
Down := True
Send, {O Down}{m Down}
Loop
{
Send, {O Down}{m Down}
Sleep, 5
Send, {O Up}{m Up}
If !Down
Break
}
Send, {O Up}{m Up}
Return
XButton1 Up::Down := False
You're telling it to send a capital 'O', and to achieve that, it sends Shift+o. So if you have some other key being pressed in the meantime, it will get shifted as well.