.Net Framework では System.Windows.Clipboard に クリップボードを扱うクラスがある。しかし、IronRuby で require ‘System.Window’ としても、no such file to load – System.Windows (LoadError) となる。
msdn のWEBリファレンスを確認すると、Assembly: PresentationCore (in PresentationCore.dll) という記述がある。IronRubyのLibにもPresentationCore.rbがあるのでこれを使う。
clipbord.rb
# coding : windows-31j
require 'PresentationCore'
require 'System.Windows.Forms'
System::Windows::Clipboard.SetText("あいうえお") #=> クリップボードに"あいうえお"をセットする。
Thread.start { system("notepad.exe") } #=> 貼り付け用アプリ起動
sleep 1 #=> notepad.exeが起動するまでスリープ ( きっと別の良い方法があるはずだが、今回は保留 )
System::Windows::Forms::SendKeys.SendWait('^V') #=> ^Vを送信することで、Ctrl + V となる。