Difference between revisions of "love.system.setClipboardText"
(Created page) |
(→Examples) |
||
(One intermediate revision by the same user not shown) | |||
Line 10: | Line 10: | ||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
+ | == Examples == | ||
+ | Set up OS agnostic keybindings for a copy paste buffer. | ||
+ | <source lang="lua"> | ||
+ | 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 | ||
+ | </source> | ||
== See Also == | == See Also == |
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
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info