You are assigning (i.e. num = 0) instead of using a conditional (i.e. if (someBool === true) {/* Do stuff */}).
Your toggle code should look something like so:
// Easiest way to toggle any value used as a boolean
self.state = !self.state;
// Or if you still want this as an if statement
if (self.state) {
self.state = 0;
} else {
// We use an else statement since there can only be two possible values
self.state = 1;
}
UPDATE: Remove the keydown event.
I just noticed that you have both a keyup and keydown event listener. Only the keyup event should be on since you want the player to press the key to toggle and then press the toggle key again