The road to programming. Hello Disney world.

Laurens Lau
2 min readMar 1, 2021

So very little keeps me focused better than writing some public report on it. Awkwardly I wish this were true for some of my scientific publications … Nonetheless I’ve been learning Python and while there’s very little impressive there, I want to share a little piece of code with you which I was able to write after going through only 2 chapters of a basic manual.

The code below:

import sys
import pyKey
import time
import random
from pyKey.windows import pressKey, releaseKey, press, showKeys, sendSequence
time.sleep(5)

for i in range(100000):
pressKey(key='4')
rand1 = random.randint(1,100)
#print(rand1*0.001)
time.sleep(rand1*0.005)
releaseKey('4')

So now what does it do? Nothing impressive mind you. It basically simulates a key stroke. More specifically it it presses the key ‘4’ one hundred thousand times with a random interval between keystrokes. The random interval goes from 5 milliseconds to half a second.

The reason it intrigues me is because I tried to simulate the simple, but actual human behaviour of someone spamming a key. The first reflection of that is the use of a module called pyKey. I don’t know the details of the module, but it makes sure that the input of the keypresses is the same as an actual keypress (as if someone put his finger on the number ‘4’ and pressed it down). This was important to me because now the program gets closer to actual human behaviour (we can control a key stroke with decent accuracy, we can’t control electric firing signal from our finger into some hardware). The second reflection of actual human behaviour is the inclusion of randomness. If you’re spamming a button, you don’t always press it with the same speed. There’s a certain variation in those intervals.

Now why would I need to simulate the human behaviour of someone spamming a key? Well mainly because I’m learning programming, and these few functions are the ones I’ve now got the knowledge for to use. Also, because I like and know a little bit about statistics, so putting a little bit of randomness in there puts me in a comfort zone. But there’s also a little bit of a story of why I considered key spamming a form of human behaviour.

A little more than a year ago (blissful pre-corona times) I was in Disneyland with my daughter. There’s an application that you can download where you can sign up for a meet-up with certain Disney characters. Frozens’ Elsa being the must-see princess, I tried to spam the ‘sign-up’ button on the application. I even convinced my sister and brother in law to help me get into a meeting, but sadly, due to popular demand and limited availability, we never even got in.

Thus it’s a real human behaviour that I wanted to replicate and this is as close as I could get for the moment.

--

--