2014-01-26 155 views
2

我该如何以Go语言进行操作?我已经使用Python 2.7,pywin32作为win32com和下面的代码来触发虚拟键盘按下。Go - 我如何在代码中执行此Python代码?

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) 

其实我想在走同样的Python代码(适用于Windows和Mac),任何人都可以给我任何例子究竟如何这可以一起去做些什么呢?

enter image description here

+0

Python代码将只在Windows上工作,因为'win32com'的。如果我理解正确,您希望可执行文件以全屏方式在“stackoverflow.com”上启动Chrome。那是对的吗? – ThinkChaos

+0

YES正好...... – YumYumYum

+0

检查[this](http://productforums.google.com/d/msg/chrome/eX15CQ602UQ/zckrLOqBU5gJ)out:make SO书签,转到'chrome:// apps',拖动创建新应用的书签,右键单击+“全屏打开”,右键单击+“创建快捷方式...”。 '创建快捷方式...'似乎只能在Windows上使用。 – ThinkChaos

回答

3

这不回答Win32调用的一部分,我认为你可以做到这一点通过系统调用包,如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) 
    } 
}