Assuming up on your joystick is mapped to the up arrow key on the keyboard, this should work:
$1::
send 1
GetKeyState, keystate, up
If (keystate = "D")
send {esc}
return
Note that you'll probably have to start holding up first and then press 1. To reverse this, simply switch up and 1 in the script.
Hope this helps.