pasteboard.paste()

类型 函数
版本 Release 2024.3703
关键词 粘贴,剪贴板
另请参见 剪贴板
pasteboard.copy()
pasteboard.clear()

概述

粘贴剪贴板上最顶部的项目。

提示

图像复制/粘贴仅受 iOS 支持。

语法

pasteboard.paste( [listener] )
listener (可选)

函数. 执行粘贴操作时需要调用的侦听器函数。该函数会传入一个 event 表,该表可能包含以下属性,具体取决于数据粘贴的类型

  • event.filename (字符串) — 已粘贴图像的名称。
  • event.baseDir (常量) — 已粘贴图像的基本系统目录。
  • event.string (字符串) — 已粘贴字符串。
  • event.url (字符串) — 已粘贴网址。

示例

local pasteboard = require( "plugin.pasteboard" )

-- Callback function for the paste method
local function onPaste( event )

    -- Print the type of data on the pasteboard
    print( "Type of data:", pasteboard.getType() )

    -- Paste an image
    if ( event.filename ) then
        print( "filename is:", event.filename )
        print( "baseDir is:", event.baseDir )
    end
    
    -- Paste a string
    if ( event.string ) then
        print( "string is:", event.string )
    end
    
    -- Paste a URL
    if ( event.url ) then
        print( "URL is:", event.url )
    end
end

pasteboard.paste( onPaste )