Clipboard
#1
Clipboard, Read and write =)
corbaque
Aug 29 2007

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Hi all !

You want use the clipboard (ctrl c & ctrl v) with RPG Maker ?

Put this script before main, named it "Clipboard" :
Code:
#===================================
# Clipboard
#---------------------------------------------------------------
# Created by Corbaque
#---------------------------------------------------------------
# Read :
# Clipboard.data
# Write :
# Clipboard.data = ""
#===================================
class Clipboard
  GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'II', 'I')
  GlobalFree = Win32API.new('kernel32', 'GlobalFree', 'I', 'I')
  GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'L', 'L')
  OpenClipboard = Win32API.new('user32', 'OpenClipboard', 'L', 'I')
  CloseClipboard = Win32API.new('user32', 'CloseClipboard', 'V', 'I')
  GetClipboardData = Win32API.new('user32', 'GetClipboardData', 'I', 'P')
  SetClipboardData = Win32API.new('user32', 'SetClipboardData', 'II', 'I')
  EmptyClipboard   = Win32API.new('user32', 'EmptyClipboard', 'V', 'I')
  Memcpy = Win32API.new('msvcrt',  'memcpy', 'IPI', 'I')
  #-------------------------------------------------------------
  # Write on clipboard
  #-------------------------------------------------------------
  def self.data=(clip_data)
    OpenClipboard.call(0)
    EmptyClipboard.call
    clip_data << "\"
    hmem = GlobalAlloc.call(0x42, clip_data.length + 4)
    mem = GlobalLock.call(hmem)
    Memcpy.call(mem, clip_data, clip_data.length)
    SetClipboardData.call(1, hmem)
    GlobalFree.call(hmem)  
    CloseClipboard.call
    self
  end
  #-------------------------------------------------------------
  # Read clipboard
  #-------------------------------------------------------------
  def self.data
    clipdata = ""
    OpenClipboard.call(0)
    begin
      clipdata = GetClipboardData.call(1)
    rescue
    end
    CloseClipboard.call
    clipdata
  end
end


To write a string on clipboard :
Code:
Clipboard.data = "Ham"


To read the clipboard (string only) :
Code:
str = Clipboard.data
print str


Enjoy it.

PS :
I can format it to an SDK version, if you want.
}




Users browsing this thread: 1 Guest(s)