Do you know someone who Karma’s been slacking on lately? Looking for a harmless April Fools’ Day prank that allows you to flex your Pythonic muscles? Well look no further. Here’s a simple little Python programming prank you can quickly code up, customize for maximum effect, and maybe even learn about a couple useful Python packages along the way.
You will want Python installed to code the prank, but the victim probably won’t need to have Python on their machine. This prank makes use of the wonderfully easy-to-use pyautogui package, which allows you to automate mouse and keyboard actions, as well as make message boxes pop up and take screenshots.
The Prank
So here’s the idea: the victim gets on their computer (after you’ve had a minute or two with it) and sees a seemingly harmless but in retrospect suspicious message that they close, which triggers their cursor to start freaking out, after which we hope the victim starts freaking out…just a little bit.
If you haven’t used pyautogui before, install it by entering the following command in Windows Command Prompt (or the Mac OS X or Linux equivalent):
1 |
pip install pyautogui |
Then have a look at some pyautogui examples to get an idea of what’s possible. Keep in mind that a fail-safe mechanism is built into pyautogui where if you move the cursor to the top-left corner of the screen (which you can usually do if you are quick with the mouse, even if the cursor’s moving quite fast on its own), an exception will be raised and the program will abort. This can be disabled, but exercise caution if you choose to do so.
Setup
Now let’s get to coding. Here’s the basic script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import time import random import pyautogui def move_mouse(how_long_in_seconds): start_time = time.time() time_elapsed = time.time() - start_time xsize, ysize = pyautogui.size() while time_elapsed < how_long_in_seconds: x, y = random.randrange(xsize), random.randrange(ysize) pyautogui.moveTo(x, y, duration=0.2) time_elapsed = time.time() - start_time if __name__ == "__main__": pyautogui.alert("Your Java update is now complete") move_mouse(120) |
Once you’ve tailored this to your liking, we’ll want to be able to run your program on your victim’s machine even if Python isn’t installed. To accomplish this, we’ll use the PyInstaller package, which “freezes” Python programs into stand-alone executables that can then be run on any machine with the same operating system as the one the program was frozen on.
Install PyInstaller if you need to:
1 |
pip install pyinstaller |
and once that’s finished, while still in your OS’s version of Command Prompt, navigate to the folder where your Python script is stored and enter the following command to initiate the creation of your executable:
1 |
pyinstaller your_prank_script.py |
This will result in PyInstaller creating 3 things:
- A file with the same name as your prank script but with the “.spec” file extension
- A folder named “build”
- A folder named “dist”
Open the “dist” folder and you will find the folder which constitutes your brand new app (and which should have the same name as your script). Going into that folder, you should see a file named “your_prank_script.exe”, and when you run it you will hopefully see your program execute like a charm without Python ever being needed.
All you need to do now is wait for an opportune moment to copy that first folder in the “dist” folder over to your victim’s machine and then run the executable. Once you run it, take a moment to position everything on their screen to your liking (a command prompt window may pop up which you’ll want to minimize) and then sit back and drink some Yoo-hoo as your prey helplessly falls for your ingenious ploy.
Wrapping Up
A few ideas on how to improve this Python programming prank:
- Make the cursor movements spell something out, perhaps the victim’s name.
- Make your program run at startup, so turning the computer off and back on doesn’t make it go away.
- Incorporate mouse clicks, keyboard actions (hotkeys to change screen orientation?), or more messages.
Or if you’re in a pinch and need something quick, there’s always the good old “mysterious and infuriating keystrokes from a wireless keyboard secretly plugged into their computer” prank.
Or just re-orient their screen upside down. For some people, that’s as mind-blowing as anything else.
In any case, good luck, and don’t get fired.
Matt says
I’ve never been so excited to go to work
Matt says
OK, so I wrote this up at home, created an exe, and successfully ran that on my home computer. I put that same file on my work computer and it won’t run; both are Windows machines. It appears to attempt to open a CMD-type of window which closes almost instantly – too quick to tell what it actually is – and the actual program never runs. Any pointers? I had a whole day of mischief planned..
Grayson Stanton says
I would guess that it has something to do with your home computer having a different version of Windows than your work computer. For example, creating the executable on a computer with Windows 10 and then running it on one with Windows 7, to my knowledge, probably won’t work. Try creating the executable on your work computer and (assuming the other computers at work have the same version of Windows) see if that works.
Grayson Stanton says
Any luck? It worked pretty well for me at the office. This guy was about to tear all the cables out of his laptop before I stopped him, haha. He was a good sport about it though.
Matt says
Sorry for the long delay – I don’t get email notifications when someone replies to these comments; I just happened to check if there were new posts and saw this. Anyhow, I figured it out .. my office computers are set up to prohibit most exe’s from running. Well, I didn’t get the satisfaction of watching a co-worker go crazy, but at least I learned something new.
Grayson Stanton says
Hi Matt, thanks for pointing that out, I’ve enabled comment subscriptions for the time being.
Too bad about your office’s security. Keep it up your sleeve for when a friend or family member deserves a prank 🙂