There's a separate function you need to define called _integrate_forces(body), anything that involves forces and impulses must be placed under it.
To keep the input stuff under the event function, you can simply define the value of a variable (like you have) and use that variable to set the torque impulse.