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.
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):
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.
Now let’s get to coding. Here’s the basic script:
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")
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:
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:
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.
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.