简体   繁体   English

替代python软件包win32api,win32com for Mac的功能

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

I am attempting to run a python candy crush bot on my Mac. 我试图在Mac上运行python糖果迷恋机器人。 Unfortunately, it appears the code as written works for Windows. 不幸的是,它看起来像是为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). 完整上下文中的代码可以在git repo的main.pymain.py (下面的链接)。 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. 我的目标是使这段代码在Macbook上运行,最终目标是编写一个类似的脚本来播放2048。像原始作者一样,我不需要跨平台运行它,尽管这样做会带来很多好处。

Now, finally, for the question: How can this functionality be implemented in a Mac? 现在,最后提出一个问题:如何在Mac中实现此功能?

References 参考文献

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

Author commentary: http://www.clickalot.me/2015/05/candy-crush-bot/#comment-4 作者评论: 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 另请参阅https://code.google.com/p/pymouse/wiki/文档

see also https://github.com/SavinaRoja/PyUserInput 另请参见https://github.com/SavinaRoja/PyUserInput

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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