复制粘贴怎么可能? [英] How is copy paste possible?

查看:107
本文介绍了复制粘贴怎么可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长时间使用计算机后,我想知道复制粘贴是基本功能,但我知道不是.那么问题是这如何真正起作用?

I was wondering after using computer for a long times it feels like copy paste was fundamental feature but I know it is not. So the question is how does this really work?

我想到了所有可能如何实现的想法,但是每次我提出不同的文件格式(例如gif,jpg,txt,png,png,mp3,mp4,JSON,YML等)时,我都会陷入困境.去复杂它就像快捷方式,链接,然后有目录.就像它以chrome方式复制搜索结果中的图像一样,有时由于限制而无法复制某些内容,也无法选择某些内容,然后就无法复制,而有时即使无法按层次结构进行选择,子对象被复制,因此它是如何实现的.

I thought of all ideas how this could have been implemented but I get stuck every time I come up with the different file formats like gif, jpg, txt, png, mp3, mp4, JSON, YML etc. and the further you go the complex it gets like shortcuts ,links and then there's directories. Like how it copies images that are in the search result in chrome whereas sometimes you can't copy something due to restriction also you can't select something then you can't copy it whereas sometimes even if you can't select in hierarchy the children are copied so how is it implemented.

但是,当有人问我复制粘贴的工作原理时,我会回答:复制内容时,它将复制的项目放入内存中,然后将其粘贴到操作系统找到的位置复制并将所有文件复制为二进制文件并将其复制.

But when someone asks me how does copy paste work generally I reply like: When something is copied then it puts the copied item to memory and when pasting it to somewhere the OS finds out the location to where it should be copied and replicates all the file to binary and copies it.

可能不正确,所以您可以解释一下它是如何工作的.知道复制粘贴代码的方式也是很有帮助的.

Which might not be true so can you explain how does it exactly work. Also it would be helpful to know how the code was written for copy paste.

推荐答案

您需要意识到的第一件事是复制和粘贴"以及拖放"是IPC(进程间通信)的一种形式因为数据正在从一个应用程序传输到另一个应用程序.这种机制通常由负责管理图形用户界面的相同子系统或服务提供.

The first thing you need to realize is that "copy and paste" as well as "drag and drop" are a form of IPC (Inter-process communication) since the data is being transferred from one application to another. This mechanism is usually provided by the same subsystem or service which is responsible for managing the graphical user interface.

此子系统为源"和目标"应用程序提供了一种机制,以协商应传输的数据格式,如果它们同意"某种通用格式,则可以传输数据.

This subsystem provides a mechanism for "source" and "destination" applications to negotiate about the format of the data that should be transferred and if they "agree" on some common format then the data can be transferred.

  1. 用户在网络浏览器中选择文本,然后按Ctrl + C.
  2. 浏览器告诉窗口系统它具有一些可用于复制的数据. 请注意,此步骤未复制任何数据.
  3. 用户打开文本编辑器,然后按Ctrl + V.
  4. 文本编辑器告诉窗口系统以纯文本格式在剪贴板上提供其内容 .
  5. 窗口系统告诉浏览器以纯文本格式提供其共享数据.
  6. 浏览器将其数据从 HTML(或其他)转换为纯文本,然后通过窗口系统将其传输到文本编辑器. 请注意,这种转换并非总是可能的(取决于格式和应用程序),因此有时您无法粘贴复制的数据.
  1. User selects the text in the web-browser and presses Ctrl+C.
  2. Browser tells the windowing system that it has some data available for copying. Note that no data is copied at this step.
  3. User opens a text editor and presses Ctrl+V.
  4. Text editor tells the windowing system to provide it the contents on the clipboard in plain-text format.
  5. Windowing system tells the browser to provide its shared data in plain-text format.
  6. Browser converts its data from HTML (or something else) to plain-text and transfers it to the text editor via windowing system. Note that this conversion is not always possible (depending on the formats and applications), hence you sometimes can't paste the copied data.

技术细节

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆