Needing help with AHK script

I am trying to get a script that will let me switch between keys. Right now I am using this script to do just the 1 key. But I want to have the same for the 2 key.

#IfWinActive World of Warcraft

$1::
GetKeyState, state, 1, P
if state = D

Loop
{
Send {1}
Sleep, 30
return
}
#IfWinActive
indent preformatted text by 4 spaces

Just do it again after }

You can use my script as an example or just use it as a whole and swap the number keys for the keys you want.

Like this?

#IfWinActive World of Warcraft
$1::
GetKeyState, state, 1, P
if state = D

Loop
{
Send {1}
Sleep, 30
return
}
$2::
GetKeyState, state, 2, P
if state = D

Loop
{
Send {2}
Sleep, 30
return
}
#IfWinActive

yes, also the second ifWinActive is redundant. Delete it.