Issue
Info: I want to make the program rotate continuasly unless a spesific keyboard button is presed. The thing is ... nothing happens when I press the button p for exapmle or whatever button i press. I will be glad if someone can help.:)
import time
import rotatescreen as rs
import keyboard
pd = rs.get_primary_display()
angel_list = [90, 180, 270, 0]
for i in range(5):
for x in angel_list:
pd.rotate_to(x)
time.sleep(0.5)
if keyboard.is_pressed("p"):
pd.rotate_to(0)
break
Solution
add_hotkey
before the loop that will call a function when pressed that will set a variable to False
which will stop the loop (also since it stops it after a full rotation no matter when p is pressed, you don't need a separate check to turn screen back to normal):
import time
import rotatescreen as rs
import keyboard
def stop():
global run
run = False
run = True
keyboard.add_hotkey('p', stop)
pd = rs.get_primary_display()
angel_list = [90, 180, 270, 0]
while run:
for x in angel_list:
pd.rotate_to(x)
time.sleep(0.5)
Answered By - Matiiss
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.