You can screw up your friend’s computer with just 6 lines of python code

RAZREXE
3 min readFeb 5, 2021

Let’s get started!

Before getting started you need to have installed python on your system and we will need to use a python editor to write the code. I will use PyCharm you can use any other editor you have and the things should run just fine, but if you want to follow me then just click on this link and get the PyCharm community version for free and install it on your system.

Simply start a new project on your PyCharm and name it something funny, I am calling it a prank,

First of all, we need the rotate-screen python package.

Click on the terminal of your PyCharm, type the following command, and hit enter.

pip install rotate-screen

And it will take only two seconds to install on your computer. Now we can proceed with the coding part. On the main.py file, write the following code:

import rotatescreen
screen = rotatescreen.get_primary_display()
screen.rotate_to(90)

If you try to run this code you will get an exception error in your console like this:

Don’t worry we can solve this easily. Simply click on your terminal again and type the following command to install the win32api module:

pip install pypiwin32

Once you are done installing the above package, you should be good to go. Simply hit Ctrl+Shift+F10 to run the main.py file and voilà! Your screen just rotated by 90 degrees :D

To get back to the 0-degree position, you need to change the value of the screen.rotate_to(90) to screen.rotate_to(0) and hit Ctrl+Shift+F10 to run the main.py file. So the code should look like this now:

import rotatescreen
screen = rotatescreen.get_primary_display()
screen.rotate_to(0)

Now that you are back to normal, here comes the fun part!

Let’s make a loop and make this program run indefinitely to make your friend completely mad at you. To do that, we just need to implement a for loop like so:

import rotatescreen
import time
screen = rotatescreen.get_primary_display()
for i in range(13):
time.sleep(1)
screen.rotate_to(i*90 % 360)

Let’s have a quick look at what we did so far. I imported the time module so we get a little interval between each flip. Then I added a for loop and as the rotations can only occur in only 0, 90, 180, and 270 degrees, so I had to mod the product of i and 90 with 360 so we get only 0, 90, 180, and 270 degrees as outputs from the loop.

You can have any value in place of the loop’s range, for example, 1000, and watch the display keep flipping forever XD

When you are satisfied by the flippy action, you can stop the loop by pressing Ctrl+F2 and that will stop the rotation of your screen. Remember to change the screen.rotate_to() value back to 0 in order to get back to 0 degree i.e. normal!

Have fun with the script, HAPPY CODING!

--

--

RAZREXE

Data engineer by profession with the skill set of a hacker, and a tech writer during tea breaks :)