2013-06-18 75 views
1

如何使用Go複製到剪貼板或從中獲取數據?如何在Go中使用剪貼板?

我有點擔心,有no results in the documentationGoogle has yielded me this result,但我想這對跨平臺工作...後來我發現this playground snippet(從該頁面),但它不會編譯(因爲「不安全」包不能在操場上使用,我得到這個,但它仍然看起來依賴於平臺。)

那麼這甚至可能,跨平臺?

+0

你的意思是Windows剪貼板? – theglauber

+0

@theglauber跨平臺。 – Matt

+1

我不認爲這存在。它必須由底層運行時提供,並且Go和其他no-Go應用程序之間沒有公共運行時。您看到的示例使用Windows'[user32.dll](http://en.wikipedia.org/wiki/Microsoft_Windows_library_files#USER32.DLL) – theglauber

回答

1

您必須將os.exec(..)輸出到特定於平臺的命令,以便從剪貼板複製到/粘貼。

或者你可以使用特定於平臺的庫來做到這一點,但我敢肯定,沒有平臺不可知的方式來訪問剪貼板。