Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Windows環境でクリップボードを操作

概要

Windows環境でクリップボードを操作

詳細

Windows環境でクリップボードを操作します。

準備

win32-clipboard gemをインストールします。

gem i win32-clipboard
サンプル
# encoding: utf-8
require 'tbpgr_utils'
require 'win32/clipboard'
 
str =<<-EOS
いちぎょうめ
にぎょうめ
さんぎょうめ
EOS
Win32::Clipboard.set_data(str, Win32::Clipboard::UNICODETEXT)
puts Win32::Clipboard.data(Win32::Clipboard::UNICODETEXT)
出力
いちぎょうめ
にぎょうめ
さんぎょうめ