love.system.setClipboardText

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Puts text in the clipboard.

Function

Synopsis

love.system.setClipboardText( text )

Arguments

string text
The new text to hold in the system's clipboard.

Returns

Nothing.

Examples

Set up OS agnostic keybindings for a copy paste buffer.

local buffer

function love.draw()

  love.graphics.print(
    "OS: "..love.system.getOS().."\n"..
    "Local buffer: "..tostring(buffer).."\n"..
    "System buffer: "..tostring(love.system.getClipboardText()))

end

function love.keypressed(key)

  local osString = love.system.getOS()

  local control

  if osString == "OS X" then
    control = love.keyboard.isDown("lgui","rgui")
  elseif osString == "Windows" or osString == "Linux" then
    control = love.keyboard.isDown("lctrl","rctrl")
  end

  if control then
    if key == "c" then
      if buffer then love.system.setClipboardText(buffer) end
    end
    if key == "v" then
      buffer = love.system.getClipboardText()
    end
  end

  -- Quite a few linux distros use the middle mouse button for paste
  if love.mouse.isDown(3) then
    buffer = love.system.getClipboardText()
  end

end

See Also

Other Languages