我怎么能用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来完成这项工作?
答案 0 :(得分:3)
这不回答win32调用部分,我假设您可以通过syscall包执行此操作,如https://github.com/AllenDang/w32
至于在全屏模式下启动Chrome,您可以通过快捷方式进行操作,或者如果您真的想从头开始操作,可以执行以下操作: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)
}
}
答案 1 :(得分:0)
win32 ole实现golang https://github.com/go-ole/go-ole