V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
meloncrashed
V2EX  ›  Python

请问 pyautogui 与 autohotkey 哪个强大一些,用过一段时间的 autohotkey 感觉语法不太舒服,变量很诡异。写过些 autohotkey 的脚本,想用 pyautogui 重写。

  •  
  •   meloncrashed · 2015-11-22 03:09:13 +08:00 · 7940 次点击
    这是一个创建于 3069 天前的主题,其中的信息可能已经有所发展或是发生改变。
    14 条回复    2019-04-02 18:56:58 +08:00
    dsp2138
        1
    dsp2138  
       2015-11-22 11:00:47 +08:00   ❤️ 1
    aauto
    mathgl
        2
    mathgl  
       2015-11-22 12:39:07 +08:00 via Android   ❤️ 1
    以前用 autoit 做过一个外单,感觉比 autohotkey 好用。
    joshz
        3
    joshz  
       2015-11-22 13:48:26 +08:00   ❤️ 1
    语言设计上明显 autoit 更好,不过 ahk 更普及,脚本更好找,目前加入了 OO ,能力不相上下了。 ahk 开源,还有一些黑科技,比如使用单个 modifier 键控制。总体还是看个人喜好, pyautogui 我没用过,不了解。
    g00001
        4
    g00001  
       2015-11-22 19:51:23 +08:00
    autoit ,以及基于 autoit 山寨出来的 ahk ,一个最主要的功能就是模拟操作控制外部的句柄窗口十几个函数(这两软件曾经为了这十几个函数的所有权打的不可开交),不过现在 direct ui 流行,基本都是无句柄窗口了,这种模拟按键的软件有些过时了。

    说到 autoit 的语言设计,真是不敢恭维,
    简单的一个调用 WINAPI 的代码,用 aardio( aauto ) 写只要一句。

    var tm = time() //创建 SYSTEMTIME
    var filetime = ::FILETIME() //创建 FILETIME
    ::Kernel32.SystemTimeToFileTime(tm,filetime) //调用 API 函数

    改成 autoit 来写吧,比写命令行还麻烦:
    ------------------------------------------------------------------
    $SYSTEMTIME = DllStructCreate("ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort")
    $lpSYSTEMTIME = DllStructGetPtr($SYSTEMTIME)
    $LOCALFILETIME=DllStructCreate("dword;dword")
    $lpLOCALFILETIME = DllStructGetPtr($LOCALFILETIME)
    DllStructSetData($SYSTEMTIME, 1, $Year)
    DllStructSetData($SYSTEMTIME, 2, $Month)
    DllStructSetData($SYSTEMTIME, 3, _DateToDayOfWeek($Year,$Month,$Day)-1)
    DllStructSetData($SYSTEMTIME, 4, $Day)
    DllStructSetData($SYSTEMTIME, 5, $Hour)
    DllStructSetData($SYSTEMTIME, 6, $Minute)
    DllStructSetData($SYSTEMTIME, 7, 0)
    DllStructSetData($SYSTEMTIME, 8, 0)
    $result = DllCall("kernel32.dll", "long", "SystemTimeToFileTime", "ptr", $lpSystemTime, "ptr", $lpLocalFileTime)
    If $result[0] = 0 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError[0])
    SetError(1)
    Return 0
    EndIf
    Hyperion
        5
    Hyperion  
       2015-11-23 08:14:17 +08:00 via Android   ❤️ 1
    @g00001 这是库设计的问题,请看一下手册里的 winapi 库,有提供封装…←_←
    jiezg
        6
    jiezg  
       2015-11-23 08:27:10 +08:00
    @dsp2138 现在改名字了 不过这个真赞
    qzane
        7
    qzane  
       2015-11-23 17:57:32 +08:00   ❤️ 1
    没有可比性吧...pyautogui 现在只能控制鼠标+键盘+截屏, hotkey 功能在计划中但暂时还没实现。主要的优势在于跨平台吧,其实看源码,至少 win 下面的部分接口很简单,即使用 c 写也不麻烦。
    meloncrashed
        8
    meloncrashed  
    OP
       2015-11-23 19:02:25 +08:00
    @qzane 新人才看完基础的 c, 想练练手请问完成自动控制在 windows7 下,需要使用什么库呀,大致几个步骤? 可以点指导方向嘛。谢谢
    meloncrashed
        9
    meloncrashed  
    OP
       2015-11-23 19:04:28 +08:00
    Windows Automation API
    只用这一个 api 就够了嘛?
    meloncrashed
        10
    meloncrashed  
    OP
       2015-11-23 19:08:43 +08:00
    @Hyperion 新人才看完基础的 c, 想练练手请问完成自动控制在 windows7 下,需要使用什么库呀,大致几个步骤? 可以点指导方向嘛。谢谢
    Hyperion
        11
    Hyperion  
       2015-11-23 19:33:06 +08:00
    @meloncrashed ahk 的语法太奇葩, 如果还是想用这类工具, 要么耐心学下 ahk 的各种魔法语句... 要么可以学习下 autoit, 有国内汉化版本, 但很久很久不更新了.

    其他语言没有用过, 所以也不好推荐.
    qzane
        12
    qzane  
       2015-11-26 20:59:14 +08:00   ❤️ 1
    @meloncrashed 直接 windows.h 就行,样例:
    ··· c
    #include <windows.h>

    void LeftClick ( )
    {
    INPUT Input={0};
    // left down
    Input.type = INPUT_MOUSE;
    Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    SendInput(1,&Input,sizeof(INPUT));

    // left up
    ZeroMemory(&Input,sizeof(INPUT));
    Input.type = INPUT_MOUSE;
    Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
    SendInput(1,&Input,sizeof(INPUT));
    }
    ```
    meloncrashed
        13
    meloncrashed  
    OP
       2015-12-01 23:21:02 +08:00
    @qzane 谢谢
    yinkaisheng
        14
    yinkaisheng  
       2019-04-02 18:56:58 +08:00
    我用 python 封装了一个 Windows UI 自动化模块
    https://github.com/yinkaisheng/Python-UIAutomation-for-Windows
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1240 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:20 · PVG 07:20 · LAX 16:20 · JFK 19:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.