Create a command, configure it to execute when the W key is pressed (I.E. leave the "Shortcut is invoked only when all keys are released" option unchecked), and add a mouse click action that presses the middle mouse button.
Then, create another command, configure it to execute when the W key is released (by checking the "Shortcut is invoked only when all keys are released" option), and add a mouse click action that releases the middle mouse button.