Let's walk through the logic of the script.
If expression_a
else if expression_b
else if expression_c
else if expression_d
If any of those evaluate as true, none of the ones below it are checked. That's the purpose of the else statement.
It's like
if something is a penny
You have $0.01
else if something is a dime
You have $0.10
else if something is a nickel
You have $0.05
else if something is a quarter
You have $0.25
If you have a dime and a nickel, you're be told it's only a dime. If you dropped the else statements, then you would be told you have X money for every type of coin you have.
Only one color of block will ever be executed whenever you hold down the b key.
If your mouse moved to the right, the yellow block is executed. Then it goes back to the top, where it's bolded in dark blue.
If you did not move your mouse to the right, and you are also not holding the a key physically, then it executes the orange/salmon block. Then it goes back to the bolded dark blue at the top.
Only if you did not move your mouse to the right and you are holding down the a key, can the green or pink blocks be chosen. The green block will execute if you instead moved the mouse to the left. The pink block will execute only if you didn't move the mouse at all, were holding down a, and you did not hold down d.
So, the corrected script should be something like this:
$b::
While GetKeyState("b","P") ; While you hold down the Space bar Physically
{
MouseGetPos, X_f, Y_f
Sleep 40
MouseGetPos, X_s, Y_s
If (X_s > X_f)
{
Send {a up} ; If a was being held down, release it
Send {d down}
}
If (X_s < X_f)
{
Send {d up} ; if d was being held down, release it
Send {a down}
}
} ; We are now out of the loop. The code below this line will only execute when you release the "b" key
If !GetKeyState("a","p") ; if you're not holding a down physically
{
Send {a up}
}
If !GetKeyState("d","p") ; if you're not holding a down physically
{
Send {d up}
}
; We did not use else statements on these last 2 If statements because we want to check both of them, and both of them could be true. If both are true, we want both actions to be executed.
return