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

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}
}

Related

How to make "BlockInput On/Off" only block keyboard inputs not mouse

As the title says, I've had trouble finding a way for my script to only block keyboard inputs during my script. Is there a method that I've overlooked to do this? Here's my code for reference:
toggle = 0
*xbutton1::
{
if GetKeyState("d", "P")
{
if GetKeyState("w", "P")
{
BlockInput On ;enabled
Send, {d up}
Send, {w up}
Send, {a down}
Send, {s down}
Send, {K}
BlockInput Off ;disabled when completed with the above actions ^ so no key inputs interfere
Sleep, -1
Send, {a up}
Send, {s up}
Send, {d down}
Send, {w down}
return
}
Thanks! I'd appreciate any info or tips.
You can create a function to only block keyboard input:
; Press F1 to block keyboard input for 10 seconds:
$F1::
BlockKeyboard("On")
Sleep, 10000
BlockKeyboard("Off")
return
BlockKeyboard(state){
Loop, 512
{
Key := Format("SC{:X}",A_Index)
If (state = "On")
Hotkey, *%Key%, KeyboardKey, On UseErrorLevel
else
Hotkey, *%Key%, KeyboardKey, Off UseErrorLevel
}
KeyboardKey:
return
}

repeat the entire AHK code

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

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}
...
}

AHK - How to hold a macro while Physical Key depressed

What I want to do is this:
Numpad3::
if(not GetKeyState("Shift" , "P") and not GetKeyState("RButton" , "P"))
{
SendInput {Shift down}
Sleep, 33
Click down right
}
Return
Numpad3 Up::
Sleep, 100
Click up right
Sleep, 33
SendInput {Shift up}
Return
But for some reason it isn't canceling when I let the button up. :(
I would suggest to use Send {RButton Down} (or Up) to send the right mouse click, instead of Click up right.
Also, you don't want to be sending random Sleep's if they are not really necessary, as it creates lag and makes the script inelegant and potentially unreadable.
Here is code which sends Control instead of RButton but it's only so I can test it within Notepad++.
Just replace Control with RButton and have a go:
*NumpadPgDn::
*Numpad3::
Send {Shift Down}{Control Down}
return
*NumpadPgDn Up::
*Numpad3 Up::
Send {Shift Up}{Control 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.