# # a small ruby script to retrieve the content of the Windows clipboard # handles strings containing zeroes # # public domain # require 'Win32API' class Clipboard OpenClipboard = Win32API.new('user32', 'OpenClipboard', ['I'], 'I') CloseClipboard = Win32API.new('user32', 'CloseClipboard', [], 'I') GetClipboardData = Win32API.new('user32', 'GetClipboardData', ['I'], 'I') GlobalLock = Win32API.new('kernel32', 'GlobalLock', ['I'], 'I') GlobalSize = Win32API.new('kernel32', 'GlobalSize', ['I'], 'I') GlobalUnlock = Win32API.new('kernel32', 'GlobalUnlock', ['I'], 'I') Memcpy = Win32API.new('kernel32', 'RtlMoveMemory', ['P', 'I', 'I'], 'I') def self.getdata sleep 0.1 while OpenClipboard.call(0) == 0 if (h = GetClipboardData.call(1)) != 0 and (p = GlobalLock.call(h)) != 0 sz = GlobalSize.call(p) ret = 0.chr * sz Memcpy.call(ret, p, sz) GlobalUnlock.call(h) end CloseClipboard.call() ret end end