Difference between revisions of "love.system.setClipboardText"

(Examples)
 
Line 43: Line 43:
 
       buffer = love.system.getClipboardText()
 
       buffer = love.system.getClipboardText()
 
     end
 
     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
  
 
end
 
end
 
</source>
 
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::love.system]]
 
* [[parent::love.system]]

Latest revision as of 01:53, 11 March 2019

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

end

See Also

Other Languages