Skip to content

Instantly share code, notes, and snippets.

@fanthos
Created June 27, 2017 10:38
Show Gist options
  • Save fanthos/2db2ea4260459dd96b76d974ff672598 to your computer and use it in GitHub Desktop.
Save fanthos/2db2ea4260459dd96b76d974ff672598 to your computer and use it in GitHub Desktop.
Plants vs Zombie keyboard shortcut
#IfWinActive, Plants vs. Zombies
CoordMode, Mouse, Client
SetMouseDelay, 0
SetDefaultMouseSpeed, 0
ClickAndRet(x) {
MouseGetPos, xold, yold
MouseMove, x*60+60, 40
MouseClick
MouseMove, xold, yold
MouseClick
}
1::ClickAndRet(1)
2::ClickAndRet(2)
3::ClickAndRet(3)
4::ClickAndRet(4)
5::ClickAndRet(5)
6::ClickAndRet(6)
7::ClickAndRet(7)
@BearSimps
Copy link

Does this only work with 3D Acceleration turned off? I've fiddled around with line 7 for a while now and I can't seem to figure out how it works. I'm incredibly new to AutoHotkey so I wouldn't be surprised if I'm missing out on some major detail.

@fanthos
Copy link
Author

fanthos commented Apr 15, 2022

The code simulate mouse move to calculated position and click, and then it move back to last mouse position and click.
It works on my device and not tested with other devices.
You should adjust L7 x*60+60 yourself to fit resolution on your screen.

@BearSimps
Copy link

You should adjust L7 x*60+60 yourself to fit resolution on your screen.

What is the resolution of your screen? Mine is 1920x1080. It definitely seems like 3D acceleration has something to do with it. It gets rid of the black bars and the side of the screen and stretches all of the sprites and ui. Is there a way to have 3D acceleration enabled and have the coordinates properly calculated?

Also, what exactly does x*60+60 do? The 2nd 60 seems to completely change the outcome.

Thanks for your fast response!

@fanthos
Copy link
Author

fanthos commented Apr 16, 2022

I havn't use this script for a long time, so not sure about 3D acceleration.

You can try to comment out L8-L10, then press key 1-7 to check if mouse pointer is at right posotion.

@BearSimps
Copy link

I havn't use this script for a long time, so not sure about 3D acceleration.

Understandable, I've been looking more into it and I think I might have figured it out.

Thanks for your time and replying to an old post!

@Daniilyus
Copy link

And where to throw the file

@fanthos
Copy link
Author

fanthos commented Feb 18, 2024

And where to throw the file

@Daniilyus
This is AHK script, so it can placed on anywhere and run it with AHK.

@stylish02
Copy link

A bit late to the party. it does work without 3d acceleration but just wondering if I would put it for the 7th line so it would work with 2560x1440? if you don't know its all good. it's working fine if I turn off acceleration.

@fanthos
Copy link
Author

fanthos commented Apr 1, 2024

I havn't play this game for awhile. The 7th line contains 3 numbers converts index number(1-7) to mouse pixel point on the toolbar button. If the result point is different, just manually adjust the numbers and make sure the mouse cursur is on the button correctly.

Not sure mouse works on 3d acceleration or not, just test it. You can comment out L8-L10(mouse click and return) and find the numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment