简体   繁体   中英

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

How can i do this in Go language please? I have used Python 2.7, pywin32 for the win32com and the following code which works to trigger virtual keyboard press.

Python code works:

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?

在此处输入图片说明

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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM