Plants vs. Zombies

Popcap, purveyors of digital crack have unleashed their latest game: Plants vs. Zombies. It’s basically tower defence where the creeps are zombies and the towers are plants. The game is a great mix of addictive gameplay, great visuals and some absolute comedic moments with Crazy Dave (He’s CRAZY!).

The game isn’t without its flaws however. One of the biggest ones is that there are no hotkeys, you have to move your mouse to the top of the screen to select new plants. There is a solution to this – AutoIt, the Windows automation tool that has been helping me in MMOs since Star Wars Galaxies. It is able to simulate any input (mouse movements, keyboard presses) and has basic support for hotkeys.

I’ve put together a script for AutoIt 3 that will set up hotkeys on the top number keys to correspond to the 10 seed slots. You can view the script here.

Edit: Gir489 from the Steam Forums has taken the script and improved it beyond all recognition. It now features windowed support, an update checker and numerous other changes. You can find details on the Steam Forums.

  • Twitter
  • Facebook
  • LinkedIn
  • RSS
  • Add to favorites
  • Digg
  • Reddit
  • Slashdot
May 14 2009
Categories: Gaming


Hi there, love your code.. Just curious, is there anyway I can link cob cannons to a hot key? and have the key press activate the topmost cannon?

Orry : 13:16 : Jun 16 2009

I used this script as a base for mine, as this did not work as-is.

Here’s my version. It works on my computer, and it disables mouse input, so slamming the mouse arround won’t effect the click event.

AutoItSetOption(“MouseCoordMode”, 0)
$registered = false
Dim $keys[10][2]

While 1
If WinActive(“Plants vs. Zombies”) Then

Func SelectPlant()
If WinActive(“Plants vs. Zombies”) Then
$slot = @HotKeyPressed
$slot -= 1;
If $slot == -1 Then
$slot = 9
$currentPosition = MouseGetPos()
MouseClick(“primary”, $keys[$slot][0], $keys[$slot][1], 1, 0)
MouseMove($currentPosition[0], $currentPosition[1], 0)

Func RegisterKeys()
If NOT $registered Then
$i = 0
$x = 190
$y = 70
While $i < 10
$keys[$i][0] = $x
$keys[$i][1] = $y
HotKeySet($i, "SelectPlant")
$x += 80
$i += 1
$registered = true

Func UnregisterKeys()
If $registered Then
$i = 0
While $i < 10
$i += 1;
$registered = false

gir489 : 00:52 : Jul 28 2009

Sorry for the last post.

Here’s a better post. It also has 2 new buttons.

gir489 : 06:28 : Jul 28 2009

Looks good. I think it might not have worked as it only works in Windowed Mode when I’ve tested. Yours looks a bit better, especially locking the mouse input.

Murray-Mint : 00:40 : Aug 10 2009

I’ve been updating PVZ Hotkeys almost religiously, adding windowed support, reducing failed dimension retrieving, and update checker, and a whole bunch of other stuff.

I pretty much used PVZ Hotkeys to learn AutoIt 3, and it’s really nice, and it turned me to AutoHotKeys, which is able to give me bunny hopping, and rapid pistol.

Anyway, here’s the link to the current project’s page:

gir489 : 23:01 : Aug 14 2009

Nice work on the thread and the support! I’ll add the links to the main article.

Murray-Mint : 14:13 : Aug 16 2009

Leave a Reply