How to make a virus with Python #2

RickA
2 min readDec 7, 2022

--

A program which makes you computer click anywhere and open apps you don’t even want to open. Sounds chaotic, doesn’t it? It is the perfect example how to annoy your friends, but also learning new libraries and new function with Python. Let’s talk about the random click virus.

Disclaimer: this article has only educational purpose, never harm or hurt anyone! It is only to learn the components of computer science.

If you want to learn more about what a virus is and how it works, check out my previous story about viruses. This time I will only explain the code and how to adjust it so you like it.

First, we need to import a library, the ‘pyautogui’. Open command prompt and typ ‘pip install pyautogui’. After some waiting, you downloaded the library you will need for this project.

Import these two libraries into your Python file. I make this with Visual Studio Code, link to download VSC.

import random, pyautogui as pyauto

Next we will make a for loop:

for i in range(3):

In this loop we have some options. The make the ‘classic’ variant of the virus, write this:

  h = random.randint(0,1080)
w = random.randint(0,1920)
pyauto.click(h,w,duration=0.3)
pyauto.hotkey('winleft', 'm')

The code is already done! But like I said, there are more possibilities. You can make the program turn your device off. You just need the coordinates of the buttons you need to press to turn it off.

Example:

An Apple device can be turned off by pressing the Apple logo in the upper left corner. Then, the cursor must go down a little bit and press on the button ‘turn off’. Lastly, another button must be pressed and you turned the device off. Pretty cool! I will give an example code.

import pyautogui as pyauto
pyauto.click(25,45,duration=0.3)
pyauto.click(430,45,duration=0.3)
pyauto.click(390,1188,duration=0.3)
pyauto.click(390,1188,duration=0.3)

With this small script, you can turn off an Apple iMac. The next example:

import pyautogui as pyauto
pyauto.click(15,1000,duration=0.3)
pyauto.click(15,700,duration=0.3)
pyauto.click(15,620,duration=0.3)
pyauto.click(15,620,duration=0.3)

Now, you can turn a Windows computer off. With some small adjustments, there are so many things possible. Think about automation, or some shortcuts and commands. Try it yourself and let me know what you made!

Thanks for reading this story and hopefully you learn something new. Make sure to follow me on Medium!

--

--

RickA

Computer Science: Python - Unity - Coding & Programming - Student - Follow me please :)