【问题标题】:Go - how can i do this python code in go code?Go - 我如何在 go 代码中执行此 python 代码?
【发布时间】:2014-02-17 07:49:08
【问题描述】:

请问我如何用 Go 语言做到这一点?我已经使用 Python 2.7、pywin32 和 win32com 以及下面的代码来触发虚拟键盘按下。

Python 代码有效:

import time
import win32com
import win32com.client

shell = win32com.client.Dispatch('WScript.Shell')
shell.Run('chrome')    
time.sleep(0.1)

shell.AppActivate('chrome')
shell.SendKeys("www.stackoverflow.com", 0)
shell.SendKeys("{Enter}", 0)

time.sleep(4)
shell.SendKeys("{F11}", 0)

我实际上是在 Go 中尝试相同的 Python 代码(适用于 Windows 和 Mac),谁能给我举个例子,如何用 Go 做到这一点?

【问题讨论】:

  • 由于win32com,您的python 代码只能在Windows 上运行。如果我理解正确,您需要一个可执行文件以全屏模式在stackoverflow.com 上启动 Chrome。对吗?
  • 检查this out :制作SO书签,转到chrome://apps,拖动书签制作新应用,右键+Open full screen,右键+Create shortcuts...Create shortcuts... 似乎只在 Windows 上可用。

标签: python windows macos go


【解决方案1】:

这不回答 win32 调用部分,我假设你可以通过 syscall 包来做到这一点,如https://github.com/AllenDang/w32

至于在全屏模式下启动 chrome,您可以通过快捷方式执行,或者如果您真的想从 go 执行,您可以这样做:Play (can't run there)

package main

import "os/exec"

func main(){
    chrome := "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
    cmd := exec.Command(chrome,"--chrome-frame","--kiosk","http://www.ibm.com")
    err := cmd.Start()
    if err != nil {
        println("Failed to start chrome:", err)
    }
}

【讨论】:

    【解决方案2】:

    golang 的 win32 ole 实现 https://github.com/go-ole/go-ole

    【讨论】:

    • 请提供链接中的基本详细信息,因为链接将来可能会过期/重定向。
    猜你喜欢
    • 1970-01-01
    • 2021-05-22
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    • 2023-03-13
    相关资源
    最近更新 更多