Home > Mobile >  I am trying to do a rotating screen python prank
I am trying to do a rotating screen python prank

Time:12-29

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

CodePudding user response:

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)

CodePudding user response:

you should do a while loop, and also increase the seconds and set the key to 'r' for reset:

import sys
import time
import rotatescreen as rs
import keyboard
n=0
pd = rs.get_primary_display()
angel_list = [90, 180, 270, 0]
def _stop():
    pd.rotate_to(0)
    sys.exit()
while True:
    for x in angel_list:
        pd.rotate_to(x)
        time.sleep(0.5)
    keyboard.add_hotkey('r',_stop)
  • Related