Forked from demus/golf_without_your_friends.py
Last active
September 18, 2022 10:02
-
-
Save rgson/f5a0ac54c137be9cef52ff34e985b858 to your computer and use it in GitHub Desktop.
Auto putt script for Golf With Your Friends (http://store.steampowered.com/app/431240/) Master Putter achievement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import time | |
user32 = ctypes.windll.user32 | |
# https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event | |
MOUSEEVENTF_MOVE = 0x0001 | |
MOUSEEVENTF_LEFTDOWN = 0x0002 | |
MOUSEEVENTF_LEFTUP = 0x0004 | |
# https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes | |
VK_F10 = 0x79 | |
VK_F11 = 0x7A | |
SCREEN_WIDTH = user32.GetSystemMetrics(0) | |
SCREEN_HEIGHT = user32.GetSystemMetrics(1) | |
def is_key_pressed(vk): | |
return bool(user32.GetKeyState(vk) & 0x1000) | |
def putt(): | |
user32.SetCursorPos(SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2) | |
user32.mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) | |
user32.mouse_event(MOUSEEVENTF_MOVE, 0, -1) | |
user32.mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) | |
while True: | |
print("Press F10 to start") | |
while not is_key_pressed(VK_F10): | |
print(".", end="") | |
time.sleep(0.5) | |
print() | |
print("Press F11 to stop") | |
while not is_key_pressed(VK_F11): | |
print(".", end="") | |
putt() | |
time.sleep(0.5) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment