英文:
How to use the clipboard in Go?
问题
我如何使用Go复制到剪贴板或从剪贴板获取数据?
我有点担心在文档中没有找到结果,并且谷歌给我这个结果,但我希望这能够跨平台运行...然后我找到了这个播放器片段(来自该页面),但它无法编译(因为“unsafe”包无法在播放器中使用,我明白这一点,但它看起来仍然是依赖于平台的)。
所以这是否可能跨平台?
英文:
How can I copy to the clipboard, or get data from it, using Go?
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?
答案1
得分: 3
剪贴板是一个特定于平台的东西,所以你应该使用第三方包。
例如,使用go-gtk。
https://github.com/mattn/go-gtk/tree/master/_example/clipboard
这将在受GTK支持的平台上工作。
英文:
Clipboard is a platform-specific thing, so you should use a third party package.
For example, use go-gtk.
https://github.com/mattn/go-gtk/tree/master/_example/clipboard
This will work on platforms which are supported by GTK.
答案2
得分: 1
你将不得不使用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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论