非常教程

Electron参考手册

剪贴板 | clipboard

剪贴板 | clipboard

在系统剪贴板上执行复制和粘贴操作。

过程:主要,渲染器

以下示例显示如何将字符串写入剪贴板:

const {clipboard} = require('electron')
clipboard.writeText('Example String')

在X Window系统上,还有一个选择剪贴板。要操纵它,你需要传递selection给每个方法:

const {clipboard} = require('electron')
clipboard.writeText('Example String', 'selection')
console.log(clipboard.readText('selection'))

Methods

clipboard模块具有以下方法:

注意:实验API将被标记为未来,并且可能会被删除。

clipboard.readText([type])

  • type String (optional)

返回String- 作为纯文本的剪贴板中的内容。

clipboard.writeText(text[, type])

  • text String
  • type String (optional)

text以纯文本的形式写入剪贴板。

clipboard.readHTML([type])

  • type String (optional)

返回String- 作为标记的剪贴板中的内容。

clipboard.writeHTML(markup[, type])

  • markup String
  • type String (optional)

写入markup剪贴板。

clipboard.readImage([type])

  • type String (optional)

返回NativeImage- 剪贴板中的图像内容。

clipboard.writeImage(image[, type])

  • image NativeImage
  • type String (optional)

写入image剪贴板。

clipboard.readRTF([type])

  • type String (optional)

返回String- 作为RTF的剪贴板中的内容。

clipboard.writeRTF(text[, type])

  • text String
  • type String (optional)

将其写入textRTF中的剪贴板。

clipboard.readBookmark() macOS Windows

Returns Object:

  • title String
  • url String

返回包含表示剪贴板中书签的键title和对象url。该titleurl值将是空的字符串时,书签不可用。

clipboard.writeBookmark(title, url[, type]) macOS Windows

  • title String
  • url String
  • type String (optional)

将书签titleurl书签写入剪贴板。

注意: Windows上的大多数应用程序不支持将书签粘贴到它们中,因此您可以使用clipboard.write书签和回退文本写入剪贴板。

clipboard.write({
  text: 'https://electron.atom.io',
  bookmark: 'Electron Homepage'
})

clipboard.readFindText() macOS

返回String- 查找粘贴板上的文本。该方法在从渲染器进程调用时使用同步IPC。无论何时激活应用程序,都会从查找粘贴板重新读取缓存的值。

clipboard.writeFindText(text) macOS

  • text String

text以纯文本形式将其写入查找粘贴板。该方法在从渲染器进程调用时使用同步IPC。

clipboard.clear([type])

  • type String (optional)

清除剪贴板内容。

clipboard.availableFormats([type])

  • type String (optional)

返回String[]- 剪贴板支持的格式数组type

clipboard.has(format[, type]) Experimental

  • format String
  • type String (optional)

返回Boolean- 剪贴板是否支持指定的format

const {clipboard} = require('electron')
console.log(clipboard.has('<p>selection</p>'))

clipboard.read(format) Experimental

  • format String

返回String- format从剪贴板中读取类型。

clipboard.readBuffer(format) Experimental

  • format String

返回Buffer- format从剪贴板中读取类型。

clipboard.writeBuffer(format, buffer[, type]) Experimental

  • format
  • buffer 缓冲
  • type 字符串(可选)

将其写入buffer剪贴板中format

clipboard.write(data[, type])

  • data 目的
    • text 字符串(可选)
    • html 字符串(可选)
    • image NativeImage(可选)
    • rtf 字符串(可选)
    • bookmark字符串(可选) - 网址at的标题text
  • type 字符串(可选)
const {clipboard} = require('electron')
clipboard.write({text: 'test', html: '<b>test</b>'})

写入data剪贴板。

剪贴板 | clipboard相关

Electron

Electron 是一个使用 JavaScript, HTML 和 CSS 等 Web 技术创建原生程序的框架,它负责比较难搞的部分,你只需把精力放在你的应用的核心上即可。

主页 https://electron.atom.io/
源码 https://github.com/electron/electron
发布版本 1.7.9

Electron目录

1.指南 | Guides
2.指南·开发 | Guides: Development
3.Webview 组件 |
4.加速器 | Accelerator
5.API
6.API·对象 | API·Objects
7.app
8.autoUpdater
9.浏览器总览 | BrowserView
10.浏览器窗口 | BrowserWindow
11.浏览器窗口代理 | BrowserWindowProxy)
12.ClientRequest
13.剪贴板 | clipboard
14.内容追踪 | contentTracing
15.小型文字档案 | Cookies
16.crashReporter
17.调试器 | Debugger
18.desktopCapturer
19.dialog
20.电子下载 | DownloadItem
21.环境变量 | Environment Variables
22.无框窗口 | Frameless Window
23.globalShortcut
24.IncomingMessage
25.ipcMain
26.IPC渲染器 | ipcRenderer
27.语言环境 | Locales
28.画面 | Menu
29.MenuItem
30.本地图像 | nativeImage
31.net
32.通知 | Notification
33.权限监控 | powerMonitor
34.权限存储拦截器 | powerSaveBlocker
35.处理 | process
36.协议 | protocol
37.远程 | remote
38.sandbox
39.屏幕 | screen
40.会话 | session
41.shell
42.系统表现 | systemPreferences
43.触摸板 | TouchBar
44.触摸板按钮 | TouchBarButton
45.触摸板颜色选择器 | TouchBarColorPicker
46.触摸板组 | TouchBarGroup
47.触摸板标签 | TouchBarLabel
48.触摸板弹出框 | TouchBarPopover
49.触摸板清理 | TouchBarScrubber
50.触摸板分段控制 | TouchBarSegmentedControl
51.触摸板滑块 | TouchBarSlider
52.触摸板间隔 | TouchBarSpacer
53.Tray
54.网页内容 | webContents
55.网页框架 | webFrame
56.网页要求 | WebRequest
57.窗口开启 | window.open