简体   繁体   中英

Alternative to the functionality of python packages win32api, win32com for Mac

I am attempting to run a python candy crush bot on my Mac. Unfortunately, it appears the code as written works for Windows.

Specifically, the code defines the following functions:

def win32_click(x, y):
    win32api.SetCursorPos((x, y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0) 

def do_move(move):
    start = move[0]
    end = move[1]

    start_w = get_desktop_coords(start)
    end_w = get_desktop_coords(end)

    win32api.SetCursorPos(start_w)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, start_w[0], start_w[1], 0, 0)
    time.sleep(0.3)
    win32api.SetCursorPos(end_w)
    time.sleep(0.3)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, end_w[0], end_w[1], 0, 0)

    win32api.SetCursorPos((1100, 1100))

As the author notes in his commentary (link below), he could not find an easy way to make it run cross-platform.

The code in its full context can be found in the git repo, in main.py (link below). My goal is to have this body of code run on my Macbook, with the ultimate goal being to write a similar script to play 2048. Like the original author, I do not need to have it run cross platform, although that would be bonus.

Now, finally, for the question: How can this functionality be implemented in a Mac?

References

Git Repo: https://github.com/AlexEne/CCrush-Bot

Author commentary: http://www.clickalot.me/2015/05/candy-crush-bot/#comment-4

$ pip install pymouse

then later

>>> from pymouse import PyMouse
>>> # instantiate an mouse object
... m = PyMouse()
>>> m.click(x,y)

see also https://code.google.com/p/pymouse/wiki/Documentation

see also https://github.com/SavinaRoja/PyUserInput

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM