dryift6733 2014-01-26 14:20
浏览 360
已采纳

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

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?

enter image description here

  • 写回答

1条回答 默认 最新

  • dougai2427 2014-01-26 15:17
    关注

    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)
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!