opus/sys/autorun/clipboard.lua

25 lines
555 B
Lua
Raw Normal View History

local Util = require('util')
2017-10-14 07:41:54 +00:00
local kernel = _G.kernel
local keyboard = _G.device.keyboard
2018-01-21 10:44:13 +00:00
local os = _G.os
local textutils = _G.textutils
2017-10-15 23:55:05 +00:00
local data
kernel.hook('clipboard_copy', function(_, args)
2018-01-24 22:39:38 +00:00
data = args[1]
2017-10-14 07:41:54 +00:00
end)
2018-01-24 22:39:38 +00:00
keyboard.addHotkey('shift-paste', function()
if type(data) == 'table' then
local s, m = pcall(textutils.serialize, data)
data = (s and m) or Util.tostring(data)
end
-- replace the event paste data with our internal data
-- args[1] = Util.tostring(data or '')
if data then
os.queueEvent('paste', data)
2018-01-21 10:44:13 +00:00
end
2017-10-14 07:41:54 +00:00
end)