Held down, stopping when it is not? Or do you want want act when the ‘t’Ĭameron Simpson The code you posted works great! I’m trying to understand your inner loop, and that depends on what It makes debugging much easierīecause the logic is clearer in the code. Pick a name whichĮxpresses what the variable means. That the ‘t’ key is currently held down? It affects how the code behavesĪlso, please pick a better name than “variable”. What does “keyboard.is_pressed” measure? That someone typed a ‘t’, or I’m wondering if this is the start/stop thing you allude to in your next Want your toggle to activate a “clock madly indefinitely” mode? print(toggle) This clicks the button every time toggle is true. “^” works because Booleans are actually implemented as a type of int,īut it is normally a poor way to think about them. You really want the logical “not” operator as above. The “^” operator is a bitwise operator - it is a numeric operation, notĪ logical one. This is better written: toggle = not toggle You can just write: variable = keyboard.is_pressed('tab') Want toggle to change when you press ‘t’ (or ‘tab’, it was ‘t’ before). Don’t do that! It resets the toggle at the top of the loop.