Some remarks inline below:
while True:
toggle = False
Don’t do that! It resets the toggle at the top of the loop. You only
want toggle to change when you press ‘t’ (or ‘tab’, it was ‘t’ before).
So don’t tread on it here.
On, you’ve got 2 loops. Why?
while True:
if keyboard.is_pressed(‘tab’):
variable = True
else:
variable = False
You can just write:
variable = keyboard.is_pressed('tab')
if variable == True:
This is better written:
if variable:
toggle^=True
This is better written:
toggle = not toggle
The “^” operator is a bitwise operator - it is a numeric operation, not
a logical one. You really want the logical “not” operator as above. The
“^” works because Booleans are actually implemented as a type of int,
but it is normally a poor way to think about them.
if toggle == True:
Again:
if toggle:
mouse.click(Button.left, 1)
time.sleep(0.01)
This clicks the button every time toggle is true. You you wantually
want your toggle to activate a “clock madly indefinitely” mode?
print(toggle)
if keyboard.is_pressed('t'):
break
I’m wondering if this is the start/stop thing you allude to in your next
post?
What does “keyboard.is_pressed” measure? That someone typed a ‘t’, or
that the ‘t’ key is currently held down? It affects how the code behaves
for you.
Also, please pick a better name than “variable”. Pick a name which
expresses what the variable means. It makes debugging much easier
because the logic is clearer in the code.
I’m trying to understand your inner loop, and that depends on what
“keyboard.is_pressed” measures. Do you want do something while ‘t’ is
held down, stopping when it is not? Or do you want want act when the ‘t’
key is pressed, once?
Cheers,
Cameron Simpson cs@cskk.id.au