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

Comments

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
RegisterKeys()
Else
UnregisterKeys()
EndIf
Sleep(100)
WEnd

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

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
WEnd
$registered = true
EndIf
EndFunc

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

gir489 : 00:52 : Jul 28 2009

Sorry for the last post.

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

http://rapidshare.com/files/260881507/Plants_Vs._Zombies_Hotkeys_AutoIt__Gir489_.rar

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: http://forums.steampowered.com/forums/showthread.php?t=927299

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