It should be a control/flag variable on the script.
Just think (and write if possible) what you want to do:
-If moving, it must emit particles
-In any other scenario must stop emitting
It means that you need a variable to register that "moving" event but be always off when not moving.
var moving = false #the variable
func _input(event):
if event.type == InputEvent.MOUSE_MOTION: #is moving
moving = true #should emit
func _process(delta):
set_emitting(moving) #if moving emit, if not, don't
moving = false #always false
#covers all the non moving situations, input will turn to true if moving
(you must turn on process and input, of course)
That is a simple way to turn on/off flags, useful in a many scenarios where no-events change behaviors.