测试一下robotgo自动化操做,顺便解决了原来的mingw版本中只有gcc,没有g++的问题

参考:https://gitee.com/veni0/robotgo#examples  可是编译不成功git

找到这个:https://gitee.com/veni0/robotgo#examplesgithub

(这里还有一篇参考:https://gitee.com/veni0/robotgo#examples )golang

原来仍是安装的Mingw有问题apache

用了github上robotgo推荐的带有zlib和libpng库的gcc环境:ide

https://github.com/go-vgo/Mingw 工具

下载好以后无需安装直接放到D盘,配置一下环境变量: D:\Mingw\bin 加入 PATH. 测试

gcc环境弄好以后。用如下代码测试:this

package main

import (
    "github.com/go-vgo/robotgo"
)

func main() {
    robotgo.ScrollMouse(10, "up")
    robotgo.MouseClick("left", true)
    robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
}

结果提示一堆错误,相似spa

d:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.2/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible d:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.2/../../../../x86_64-w64-mingw32/lib/libmingwthrd.a when searching for -lmingwthrd
d:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.8.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lmingwthrd

一翻搜索,在https://stackoverflow.com/questions/14990222/skipping-incompatible-cannot-find的一位名叫Michael Burr的answer提醒了我,意思大概就是说须要32位的lib,因此不匹配当前的64位的libcode

因而修改liteide工具条上的环境设置,原来的是win32-user  改成 system  。liteide提示GOARCH 变成了 amd64.  从新Ctrl-R,成功运行。

这时发现鼠标已经不受控了,心中一惊。好在还有键盘快捷方式,用Alt+B  及光标中止了liteide的运行(其实当鼠标移动到位后程序就自动结束了)。

另外还有一个小插曲,下载解压mingw后提示一堆的病毒,网上也有抱怨360的,由于360是公司要求装的,不能卸载。最后将mingw目录加入360的设置白名单。

补充一个例子,由于公司业务只能用IE,有个ActiveX。试试操做IE打开百度进行搜索,代码以下:

package main

import (
    "os/exec"

    "github.com/go-vgo/robotgo"
)

func main() {
    //启动IE,打开百度
    exec.Command("cmd", "/c", "start", "iexplore.exe", "www.baidu.com").Run()
    //等待
    robotgo.MilliSleep(5 * 1000)
    // get current Window Active
    mdata := robotgo.GetActive()
    // set Window Active
    robotgo.SetActive(mdata)
    robotgo.TypeString("pu369")
    robotgo.KeyTap("space")
    robotgo.TypeString("golang")
    robotgo.KeyTap("enter")
    robotgo.MilliSleep(5 * 1000)
    // close current Window
    robotgo.CloseWindow()

}

最后看了一下,github源代码有个什么Apache License,虽然咱属于“合理利用”,也不知道应该和谁辩论合理不合理,仍是似懂非懂地按要求附上Apache License以下:

// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
相关文章
相关标签/搜索