I'm ussing toggle switch to type a '7' when button is active. But he keeps repeating the same "7". What I want to achieve is that it will only type or press once even if the switch is active. I edited the code I added.
Here I first initialise a variable name "state".
Now if(digitalRead(7) == 0 && state==0) checks if you have pressed the button on pin 7 and the state== 0 assure that this is first time functions is executing. After that the state=1 represent that the function Keyboard.write('7') has already executed. And the statement if(digitalRead(7) == 0 && state==0) is no longer true.
Now when you release the button the second statement if(digitalRead(7) != 0) reset state to 0. And the loop continues.
That because only one statement can be true at a time. Either digitalRead(7) != 0 or digitalRead(7) == 0