How to use the clipboard in Go?

左心房为你撑大大i 提交于 2019-12-11 08:11:12

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17178617/how-to-use-the-clipboard-in-go

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!