如何在Go中使用剪贴板? [英] How to use the clipboard in Go?

查看:546
本文介绍了如何在Go中使用剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Go复制到剪贴板或从剪贴板获取数据?

How can I copy to the clipboard, or get data from it, using Go?

我有点担心有文档中没有结果 Google为我提供了此结果,但是我希望它可以跨平台工作...然后我发现此运动场片段(从该页面开始),但无法编译(因为 unsafe包不能在在操场上,我明白了,但它仍然依赖于平台。)

I'm a bit concerned that there are no results in the documentation and Google has yielded me this result, but I want this to work cross-platform... then I found this playground snippet (from that page) but it doesn't compile (because the "unsafe" package can't be used in the playground, I get this, but it still looks platform-dependent).

那么跨平台甚至有可能吗?

So is this even possible, cross-platform?

推荐答案

您必须将os.exec(..)导出到特定于平台的命令中,才能从剪贴板中复制/粘贴。

You'll have to os.exec(..) out to the platform-specific command for copying-to/pasting-from the clipboard.

或者您可以使用特定于平台的库来执行此操作,但是我很确定这是访问剪贴板的平台无关的方法。

Or you could use platform-specific libraries to do this, but I'm pretty sure there's no platform agnostic way to access the clipboard.

这篇关于如何在Go中使用剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆