简体   繁体   English

Go - 我如何在 Go 代码中执行此 python 代码?

[英]Go - how can i do this python code in go code?

How can i do this in Go language please?请问我如何用 Go 语言做到这一点? I have used Python 2.7, pywin32 for the win32com and the following code which works to trigger virtual keyboard press.我使用了 Python 2.7,pywin32 用于 win32com 和以下用于触发虚拟键盘按下的代码。

Python code works: 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)

i am actually trying the same Python code in Go (for Windows and Mac), can anyone give me any example how exactly this can be done with Go?我实际上正在 Go 中尝试相同的 Python 代码(适用于 Windows 和 Mac),谁能给我任何例子,如何用 Go 完成?

在此处输入图片说明

This doesn't answer the win32 calls part, I assume you can do that via the syscall package, as in https://github.com/AllenDang/w32这不回答 win32 调用部分,我假设您可以通过 syscall 包来做到这一点,如https://github.com/AllenDang/w32

As for launching chrome in full screen mode, you can do from a shortcut or if you really want to do it from go, you can do: Play (can't run there)至于在全屏模式下启动 chrome,您可以从快捷方式执行,或者如果您真的想从 go 执行,您可以执行以下操作:播放(不能在那里运行)

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)
    }
}

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

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

相关问题 如何让python返回到一行代码? - How do I get python to go back to a line of code? 我怎样才能回到以前的 Python 代码? - How can I go back to previous code in Python? 如何在 VS 代码中获得 Go 代码的 Python 代码着色? - How can I get Python's code coloring for Go code in VS code? 您如何在Python中创建“回到这一点”代码? - How do you create a “go back to this point” code in Python? 我们如何 go 回到 Python 中的前一行代码,就像我们在 Fortran 中所做的那样 - How can we go back a previous line of code in Python like we could do in Fortran 如何在 Visual Studio Code 中跨 python 文件转到符号 - How can I go to symbol across python files in Visual Studio Code 我将如何创建一个可以从应用程序内部更改 Python 代码的应用程序? - How would I go about creating an app that can change python code from within the app? 如何将 go 回到 Python 中的前一部分代码? - How to go back to a previous part of the code in Python? 空闲-Python:回到某一行,我该怎么做? - IDLE - Python: Go back to a certain line, how can I do this? 我将如何使用Python代码扩展我的PHP代码库? - How would I go about expanding my PHP code library with Python code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM