# How to copy data to clipboard

**URL:** <https://www.ruby-forum.com/t/how-to-copy-data-to-clipboard/150623>\
**Category:** Ruby\
**Created:** [October 10, 2008, 3:31pm UTC](https://www.ruby-forum.com/t/how-to-copy-data-to-clipboard/150623 "2008-10-10T15:31:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 10, 2008, 3:31pm UTC](https://www.ruby-forum.com/t/how-to-copy-data-to-clipboard/150623/1 "2008-10-10T15:31:49Z")

</div>

Hi all,

I want to send the word “copy” to the clipboard and trigger an event  
like ctrl-c. which gem/library is used for this purpose?

Thanks,

Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 10, 2008, 3:55pm UTC](https://www.ruby-forum.com/t/how-to-copy-data-to-clipboard/150623/2 "2008-10-10T15:55:55Z")

</div>

Li Chen wrote:

> Hi all,
> 
> I want to send the word “copy” to the clipboard and trigger an event  
> like ctrl-c. which gem/library is used for this purpose?

It depends what platform you’re using.

For Win32 only, I’d expect you could use Win32API to do this, though  
I’ve no idea what API call you’d need.

For OS X only, I’d look into Ruby-Cocoa or MacRuby. Again, I don’t know  
the specific API call needed.

For Linux/GTK only, try GTK-Ruby. Although GTK is meant to be somewhat  
cross-platform, I remember reading somewhere that clipboard functions  
don’t work on Windows. This bug may be fixed now, however.

For a cross-platform solution, try one of the cross-platform toolkits,  
either QT, FxRuby or wxRuby. With wxRuby, you would use the  
Wx::Clipboard and Wx::TextDataObject classes.

a
