How do Ctrl+C and Ctrl+V work?Outlook 2003 adds extra line feeds in pasted textCtrl key combinations don't work on a hp 2510pCannot paste web page images in Word 2010How does copying files work with regards to RAM, and can I speed this up?Win 7 accessing large files uses 100% RAMExcel copy-paste: always match destination formattingShift, fn, ctrl, alt, right and left touchpad isn't workingExcel chart into Word - losing underlinesForce Word 2013 to always paste images in-line with text

What do different value notes on the same line mean?

Infinite Sequence based on Simple Rule

Why is this Simple Puzzle impossible to solve?

Why without the JSON.parse method, I can't sort the data in lightning-datatable?

Is it possible to play as a necromancer skeleton?

Is there a down side to setting the sampling time of a SAR ADC as long as possible?

I think I may have violated academic integrity last year - what should I do?

Is there a way to make it so the cursor is included when I prtscr key?

Where is the logic in castrating fighters?

What's the Difference between Two Single-Quotes and One Double-Quote?

At what point in European history could a government build a printing press given a basic description?

What does the view outside my ship traveling at light speed look like?

When and what was the first 3D acceleration device ever released?

Python program to convert a 24 hour format to 12 hour format

What are the benefits of cryosleep?

Array Stutter Implementation

Seed ship, unsexed person, cover has golden person attached to ship by umbilical cord

Integrating an absolute function using Mathematica

What is the largest (size) solid object ever dropped from an airplane to impact the ground in freefall?

Why doesn't the Earth's acceleration towards the Moon accumulate to push the Earth off its orbit?

Logarithm of dependent variable is uniformly distributed. How to calculate a confidence interval for the mean?

Why does the 'metric Lagrangian' approach appear to fail in Newtonian mechanics?

Binary Search in C++17

What is the difference between “/private/var/vm” and “/vm”?



How do Ctrl+C and Ctrl+V work?


Outlook 2003 adds extra line feeds in pasted textCtrl key combinations don't work on a hp 2510pCannot paste web page images in Word 2010How does copying files work with regards to RAM, and can I speed this up?Win 7 accessing large files uses 100% RAMExcel copy-paste: always match destination formattingShift, fn, ctrl, alt, right and left touchpad isn't workingExcel chart into Word - losing underlinesForce Word 2013 to always paste images in-line with text






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








97















I was always wondering what happens under the hood (in the operating system) when I copy an image (selecting it and using Ctrl+C) into a Word file (pasting it with Ctrl+V), for example.










share|improve this question



















  • 42





    What level of detail do you expect?

    – grawity
    May 14 at 11:49






  • 11





    Let begin with this docs.microsoft.com/en-us/windows/desktop/dataxchg/clipboard.

    – Biswapriyo
    May 14 at 11:58






  • 4





    @Biswapriyo doesn't linux also support this kind of functionality? grawity: I said in terms of operating systems, I guess the information is stored in a temporary pipe? I'm more intrigued with images, how can they be copied so easily

    – Inter Sys
    May 14 at 12:04






  • 6





    @InterSys: Indeed, this differs a lot between different operating systems. The link given by Biswapriyo gives the details on the Microsoft Windows platform.

    – Andreas Rejbrand
    May 14 at 14:20






  • 1





    @InterSys BTW, if providing additional details about your question, you may/should incorporate them into a question itself if you consider them vital; comments can/will be pruned occasionally by mods, so the information you provided there are often lost.

    – vaxquis
    May 15 at 13:42

















97















I was always wondering what happens under the hood (in the operating system) when I copy an image (selecting it and using Ctrl+C) into a Word file (pasting it with Ctrl+V), for example.










share|improve this question



















  • 42





    What level of detail do you expect?

    – grawity
    May 14 at 11:49






  • 11





    Let begin with this docs.microsoft.com/en-us/windows/desktop/dataxchg/clipboard.

    – Biswapriyo
    May 14 at 11:58






  • 4





    @Biswapriyo doesn't linux also support this kind of functionality? grawity: I said in terms of operating systems, I guess the information is stored in a temporary pipe? I'm more intrigued with images, how can they be copied so easily

    – Inter Sys
    May 14 at 12:04






  • 6





    @InterSys: Indeed, this differs a lot between different operating systems. The link given by Biswapriyo gives the details on the Microsoft Windows platform.

    – Andreas Rejbrand
    May 14 at 14:20






  • 1





    @InterSys BTW, if providing additional details about your question, you may/should incorporate them into a question itself if you consider them vital; comments can/will be pruned occasionally by mods, so the information you provided there are often lost.

    – vaxquis
    May 15 at 13:42













97












97








97


14






I was always wondering what happens under the hood (in the operating system) when I copy an image (selecting it and using Ctrl+C) into a Word file (pasting it with Ctrl+V), for example.










share|improve this question
















I was always wondering what happens under the hood (in the operating system) when I copy an image (selecting it and using Ctrl+C) into a Word file (pasting it with Ctrl+V), for example.







memory paste ctrl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 15 at 15:40









Worthwelle

2,89331325




2,89331325










asked May 14 at 10:51









Inter SysInter Sys

524126




524126







  • 42





    What level of detail do you expect?

    – grawity
    May 14 at 11:49






  • 11





    Let begin with this docs.microsoft.com/en-us/windows/desktop/dataxchg/clipboard.

    – Biswapriyo
    May 14 at 11:58






  • 4





    @Biswapriyo doesn't linux also support this kind of functionality? grawity: I said in terms of operating systems, I guess the information is stored in a temporary pipe? I'm more intrigued with images, how can they be copied so easily

    – Inter Sys
    May 14 at 12:04






  • 6





    @InterSys: Indeed, this differs a lot between different operating systems. The link given by Biswapriyo gives the details on the Microsoft Windows platform.

    – Andreas Rejbrand
    May 14 at 14:20






  • 1





    @InterSys BTW, if providing additional details about your question, you may/should incorporate them into a question itself if you consider them vital; comments can/will be pruned occasionally by mods, so the information you provided there are often lost.

    – vaxquis
    May 15 at 13:42












  • 42





    What level of detail do you expect?

    – grawity
    May 14 at 11:49






  • 11





    Let begin with this docs.microsoft.com/en-us/windows/desktop/dataxchg/clipboard.

    – Biswapriyo
    May 14 at 11:58






  • 4





    @Biswapriyo doesn't linux also support this kind of functionality? grawity: I said in terms of operating systems, I guess the information is stored in a temporary pipe? I'm more intrigued with images, how can they be copied so easily

    – Inter Sys
    May 14 at 12:04






  • 6





    @InterSys: Indeed, this differs a lot between different operating systems. The link given by Biswapriyo gives the details on the Microsoft Windows platform.

    – Andreas Rejbrand
    May 14 at 14:20






  • 1





    @InterSys BTW, if providing additional details about your question, you may/should incorporate them into a question itself if you consider them vital; comments can/will be pruned occasionally by mods, so the information you provided there are often lost.

    – vaxquis
    May 15 at 13:42







42




42





What level of detail do you expect?

– grawity
May 14 at 11:49





What level of detail do you expect?

– grawity
May 14 at 11:49




11




11





Let begin with this docs.microsoft.com/en-us/windows/desktop/dataxchg/clipboard.

– Biswapriyo
May 14 at 11:58





Let begin with this docs.microsoft.com/en-us/windows/desktop/dataxchg/clipboard.

– Biswapriyo
May 14 at 11:58




4




4





@Biswapriyo doesn't linux also support this kind of functionality? grawity: I said in terms of operating systems, I guess the information is stored in a temporary pipe? I'm more intrigued with images, how can they be copied so easily

– Inter Sys
May 14 at 12:04





@Biswapriyo doesn't linux also support this kind of functionality? grawity: I said in terms of operating systems, I guess the information is stored in a temporary pipe? I'm more intrigued with images, how can they be copied so easily

– Inter Sys
May 14 at 12:04




6




6





@InterSys: Indeed, this differs a lot between different operating systems. The link given by Biswapriyo gives the details on the Microsoft Windows platform.

– Andreas Rejbrand
May 14 at 14:20





@InterSys: Indeed, this differs a lot between different operating systems. The link given by Biswapriyo gives the details on the Microsoft Windows platform.

– Andreas Rejbrand
May 14 at 14:20




1




1





@InterSys BTW, if providing additional details about your question, you may/should incorporate them into a question itself if you consider them vital; comments can/will be pruned occasionally by mods, so the information you provided there are often lost.

– vaxquis
May 15 at 13:42





@InterSys BTW, if providing additional details about your question, you may/should incorporate them into a question itself if you consider them vital; comments can/will be pruned occasionally by mods, so the information you provided there are often lost.

– vaxquis
May 15 at 13:42










1 Answer
1






active

oldest

votes


















156














In Windows, the clipboard API and storage buffer are provided by the OS at kernel level. (The clipboard belongs to the "window station" kernel object.)




  • Ctrl+C tells the program to store the "copied" data using the Win32 API function SetClipboardData(), which also corresponds to NtUserSetClipboardData() in the Native API.



    Normally, the copied data is immediately stored in the OS-managed clipboard buffer and no longer depends on the source program. The program can provide several different formats – e.g. text copied from MS Word can come in HTML, RTF, and plaintext formats simultaneously.



    (However, the program may store 'null' data and defer conversion until a paste is requested using WM_RENDERFORMAT. In this case data is lost when the program is closed. I'm not sure how common this method is.)



  • Ctrl+V tells the program to choose the desired format and retrieve it using GetClipboardData(). Some programs, e.g. WordPad or Paint, have a "Paste as" feature that lets you choose the preferred format (e.g. if you copied HTML but don't want formatting).


  • See also "NT Debugging: How the clipboard works" blog post.


In Linux, there is no system-wide clipboard, instead it is provided by whatever graphical environment you're using (that is, X11, Wayland, none):



In X11 (not necessarily limited to Linux), clipboard transfer is deferred. That is, the storage is provided by the 'source' program. The exchange is done via X11 messages according to the ICCCM protocol (therefore the clipboard is isolated to the X server):




  • Ctrl+C tells the source program to reserve the "copied" data in its own memory, and to claim the X11 selection called 'CLIPBOARD'. This is done using XSetSelectionOwner(), and the ownership is tracked by the X server (Xorg).



    If you had copied something previously, the previous selection owner is informed about this and discards the now-unneeded data.



    If you close the program, the copied data is lost. (Clipboard managers can be used to avoid this by watching and duplicating the current selection.)



  • Ctrl+V tells the destination program to look up the current owner of the 'CLIPBOARD' selection using XGetSelectionOwner(), then directly asks it for the preferred type using XConvertSelection(). The source program then returns the data via another X11 message, converted on-demand to the type that was requested. (There is also a special type which returns a list of possible types.)


  • See this link for a practical example.


(Note: When you "copy" text by selecting it and paste it using middle-click, the mechanism is the same but the 'PRIMARY' selection is used instead. This is where the term 'X11 selection' comes from.)



In Wayland – I don't actually understand how it works, all I have is the protocol docs:



  • https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-data-sharing


  • https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_data_device


  • See https://github.com/bugaevc/wl-clipboard for a command-line tool.


Traditional text editors (Vim, emacs, nano) often have their own internal clipboards (aka buffers/killrings). They might, or might not, also integrate with the X11 clipboard.



In macOS, something called a "pasteboard server" appears to be used (which I think means that programs communicate with it through Mach APIs). Other than that, it behaves like the Windows clipboard and stores the currently copied data itself.



  • https://developer.apple.com/documentation/appkit/nspasteboard


  • There is a sample application: https://developer.apple.com/library/archive/samplecode/ClipboardViewer/Introduction/Intro.html



I'm more intrigued with images, how can they be copied so easily




Images are just chunks of binary data, like text or audio. The clipboard will usually hold an image in formats common to the OS, e.g. BMP on Windows, image/png on Linux.



And on Linux, the X11 clipboard protocol actually allows one X client to offer different "encodings" of the selection to other clients, and the receiving X client can choose the encoding, so the sending X client gets to convert the selection into whatever format both clients understand. At least in theory; not sure if modern toolkit libraries like GTK or Qt do offer much choice.






share|improve this answer




















  • 1





    Do X11 clipboard managers request all the available formats when they steal ownership from the original owner?

    – Ruslan
    May 14 at 15:57







  • 3





    Re: I'm not sure how common this method is, I have only ever noticed it in Word, Powerpoint and Publisher (suggesting that perhaps only Microsoft ever bothers to implement it). When you click close on the application, it asks if you wish to save the clipboard. I've only seen it happen when there's a large (>1MB) image on the clipboard.

    – Tim
    May 14 at 22:36






  • 10





    @AndrewSavinykh Technically these keyboard shortcuts must be interpreted by the specific application which must then call the appropriate API to fetch the data. But most applications rely on standard frameworks which provide widgets that implement these "standard" keyboard shortcuts, e.g. the basic Win32 Edit Control implements its own handling for Ctrl+C/Ctrl+V. So: applications that draw "from scratch" must implement shortcut handling, while applications that use existing frameworks often get it "for free".

    – Bob
    May 15 at 1:02







  • 3





    Also note, that in Linux, CTRL+C does not necessarily copy a text. In text terminals, which also holds for terminals in GUIs, CTRL+C usually treated as terminating the currently running process.

    – rexkogitans
    May 15 at 6:01







  • 2





    @ErinB: That very much depends on what type is common between the two programs... there is nothing that would stop e.g. a video editor from including all frames in its own format, but usually it'll only be understood by that same program, everyone else must resort to pasting generic single-frame formats. Same goes for MS Office data, for example.

    – grawity
    May 15 at 16:58











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "3"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1436622%2fhow-do-ctrlc-and-ctrlv-work%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









156














In Windows, the clipboard API and storage buffer are provided by the OS at kernel level. (The clipboard belongs to the "window station" kernel object.)




  • Ctrl+C tells the program to store the "copied" data using the Win32 API function SetClipboardData(), which also corresponds to NtUserSetClipboardData() in the Native API.



    Normally, the copied data is immediately stored in the OS-managed clipboard buffer and no longer depends on the source program. The program can provide several different formats – e.g. text copied from MS Word can come in HTML, RTF, and plaintext formats simultaneously.



    (However, the program may store 'null' data and defer conversion until a paste is requested using WM_RENDERFORMAT. In this case data is lost when the program is closed. I'm not sure how common this method is.)



  • Ctrl+V tells the program to choose the desired format and retrieve it using GetClipboardData(). Some programs, e.g. WordPad or Paint, have a "Paste as" feature that lets you choose the preferred format (e.g. if you copied HTML but don't want formatting).


  • See also "NT Debugging: How the clipboard works" blog post.


In Linux, there is no system-wide clipboard, instead it is provided by whatever graphical environment you're using (that is, X11, Wayland, none):



In X11 (not necessarily limited to Linux), clipboard transfer is deferred. That is, the storage is provided by the 'source' program. The exchange is done via X11 messages according to the ICCCM protocol (therefore the clipboard is isolated to the X server):




  • Ctrl+C tells the source program to reserve the "copied" data in its own memory, and to claim the X11 selection called 'CLIPBOARD'. This is done using XSetSelectionOwner(), and the ownership is tracked by the X server (Xorg).



    If you had copied something previously, the previous selection owner is informed about this and discards the now-unneeded data.



    If you close the program, the copied data is lost. (Clipboard managers can be used to avoid this by watching and duplicating the current selection.)



  • Ctrl+V tells the destination program to look up the current owner of the 'CLIPBOARD' selection using XGetSelectionOwner(), then directly asks it for the preferred type using XConvertSelection(). The source program then returns the data via another X11 message, converted on-demand to the type that was requested. (There is also a special type which returns a list of possible types.)


  • See this link for a practical example.


(Note: When you "copy" text by selecting it and paste it using middle-click, the mechanism is the same but the 'PRIMARY' selection is used instead. This is where the term 'X11 selection' comes from.)



In Wayland – I don't actually understand how it works, all I have is the protocol docs:



  • https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-data-sharing


  • https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_data_device


  • See https://github.com/bugaevc/wl-clipboard for a command-line tool.


Traditional text editors (Vim, emacs, nano) often have their own internal clipboards (aka buffers/killrings). They might, or might not, also integrate with the X11 clipboard.



In macOS, something called a "pasteboard server" appears to be used (which I think means that programs communicate with it through Mach APIs). Other than that, it behaves like the Windows clipboard and stores the currently copied data itself.



  • https://developer.apple.com/documentation/appkit/nspasteboard


  • There is a sample application: https://developer.apple.com/library/archive/samplecode/ClipboardViewer/Introduction/Intro.html



I'm more intrigued with images, how can they be copied so easily




Images are just chunks of binary data, like text or audio. The clipboard will usually hold an image in formats common to the OS, e.g. BMP on Windows, image/png on Linux.



And on Linux, the X11 clipboard protocol actually allows one X client to offer different "encodings" of the selection to other clients, and the receiving X client can choose the encoding, so the sending X client gets to convert the selection into whatever format both clients understand. At least in theory; not sure if modern toolkit libraries like GTK or Qt do offer much choice.






share|improve this answer




















  • 1





    Do X11 clipboard managers request all the available formats when they steal ownership from the original owner?

    – Ruslan
    May 14 at 15:57







  • 3





    Re: I'm not sure how common this method is, I have only ever noticed it in Word, Powerpoint and Publisher (suggesting that perhaps only Microsoft ever bothers to implement it). When you click close on the application, it asks if you wish to save the clipboard. I've only seen it happen when there's a large (>1MB) image on the clipboard.

    – Tim
    May 14 at 22:36






  • 10





    @AndrewSavinykh Technically these keyboard shortcuts must be interpreted by the specific application which must then call the appropriate API to fetch the data. But most applications rely on standard frameworks which provide widgets that implement these "standard" keyboard shortcuts, e.g. the basic Win32 Edit Control implements its own handling for Ctrl+C/Ctrl+V. So: applications that draw "from scratch" must implement shortcut handling, while applications that use existing frameworks often get it "for free".

    – Bob
    May 15 at 1:02







  • 3





    Also note, that in Linux, CTRL+C does not necessarily copy a text. In text terminals, which also holds for terminals in GUIs, CTRL+C usually treated as terminating the currently running process.

    – rexkogitans
    May 15 at 6:01







  • 2





    @ErinB: That very much depends on what type is common between the two programs... there is nothing that would stop e.g. a video editor from including all frames in its own format, but usually it'll only be understood by that same program, everyone else must resort to pasting generic single-frame formats. Same goes for MS Office data, for example.

    – grawity
    May 15 at 16:58















156














In Windows, the clipboard API and storage buffer are provided by the OS at kernel level. (The clipboard belongs to the "window station" kernel object.)




  • Ctrl+C tells the program to store the "copied" data using the Win32 API function SetClipboardData(), which also corresponds to NtUserSetClipboardData() in the Native API.



    Normally, the copied data is immediately stored in the OS-managed clipboard buffer and no longer depends on the source program. The program can provide several different formats – e.g. text copied from MS Word can come in HTML, RTF, and plaintext formats simultaneously.



    (However, the program may store 'null' data and defer conversion until a paste is requested using WM_RENDERFORMAT. In this case data is lost when the program is closed. I'm not sure how common this method is.)



  • Ctrl+V tells the program to choose the desired format and retrieve it using GetClipboardData(). Some programs, e.g. WordPad or Paint, have a "Paste as" feature that lets you choose the preferred format (e.g. if you copied HTML but don't want formatting).


  • See also "NT Debugging: How the clipboard works" blog post.


In Linux, there is no system-wide clipboard, instead it is provided by whatever graphical environment you're using (that is, X11, Wayland, none):



In X11 (not necessarily limited to Linux), clipboard transfer is deferred. That is, the storage is provided by the 'source' program. The exchange is done via X11 messages according to the ICCCM protocol (therefore the clipboard is isolated to the X server):




  • Ctrl+C tells the source program to reserve the "copied" data in its own memory, and to claim the X11 selection called 'CLIPBOARD'. This is done using XSetSelectionOwner(), and the ownership is tracked by the X server (Xorg).



    If you had copied something previously, the previous selection owner is informed about this and discards the now-unneeded data.



    If you close the program, the copied data is lost. (Clipboard managers can be used to avoid this by watching and duplicating the current selection.)



  • Ctrl+V tells the destination program to look up the current owner of the 'CLIPBOARD' selection using XGetSelectionOwner(), then directly asks it for the preferred type using XConvertSelection(). The source program then returns the data via another X11 message, converted on-demand to the type that was requested. (There is also a special type which returns a list of possible types.)


  • See this link for a practical example.


(Note: When you "copy" text by selecting it and paste it using middle-click, the mechanism is the same but the 'PRIMARY' selection is used instead. This is where the term 'X11 selection' comes from.)



In Wayland – I don't actually understand how it works, all I have is the protocol docs:



  • https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-data-sharing


  • https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_data_device


  • See https://github.com/bugaevc/wl-clipboard for a command-line tool.


Traditional text editors (Vim, emacs, nano) often have their own internal clipboards (aka buffers/killrings). They might, or might not, also integrate with the X11 clipboard.



In macOS, something called a "pasteboard server" appears to be used (which I think means that programs communicate with it through Mach APIs). Other than that, it behaves like the Windows clipboard and stores the currently copied data itself.



  • https://developer.apple.com/documentation/appkit/nspasteboard


  • There is a sample application: https://developer.apple.com/library/archive/samplecode/ClipboardViewer/Introduction/Intro.html



I'm more intrigued with images, how can they be copied so easily




Images are just chunks of binary data, like text or audio. The clipboard will usually hold an image in formats common to the OS, e.g. BMP on Windows, image/png on Linux.



And on Linux, the X11 clipboard protocol actually allows one X client to offer different "encodings" of the selection to other clients, and the receiving X client can choose the encoding, so the sending X client gets to convert the selection into whatever format both clients understand. At least in theory; not sure if modern toolkit libraries like GTK or Qt do offer much choice.






share|improve this answer




















  • 1





    Do X11 clipboard managers request all the available formats when they steal ownership from the original owner?

    – Ruslan
    May 14 at 15:57







  • 3





    Re: I'm not sure how common this method is, I have only ever noticed it in Word, Powerpoint and Publisher (suggesting that perhaps only Microsoft ever bothers to implement it). When you click close on the application, it asks if you wish to save the clipboard. I've only seen it happen when there's a large (>1MB) image on the clipboard.

    – Tim
    May 14 at 22:36






  • 10





    @AndrewSavinykh Technically these keyboard shortcuts must be interpreted by the specific application which must then call the appropriate API to fetch the data. But most applications rely on standard frameworks which provide widgets that implement these "standard" keyboard shortcuts, e.g. the basic Win32 Edit Control implements its own handling for Ctrl+C/Ctrl+V. So: applications that draw "from scratch" must implement shortcut handling, while applications that use existing frameworks often get it "for free".

    – Bob
    May 15 at 1:02







  • 3





    Also note, that in Linux, CTRL+C does not necessarily copy a text. In text terminals, which also holds for terminals in GUIs, CTRL+C usually treated as terminating the currently running process.

    – rexkogitans
    May 15 at 6:01







  • 2





    @ErinB: That very much depends on what type is common between the two programs... there is nothing that would stop e.g. a video editor from including all frames in its own format, but usually it'll only be understood by that same program, everyone else must resort to pasting generic single-frame formats. Same goes for MS Office data, for example.

    – grawity
    May 15 at 16:58













156












156








156







In Windows, the clipboard API and storage buffer are provided by the OS at kernel level. (The clipboard belongs to the "window station" kernel object.)




  • Ctrl+C tells the program to store the "copied" data using the Win32 API function SetClipboardData(), which also corresponds to NtUserSetClipboardData() in the Native API.



    Normally, the copied data is immediately stored in the OS-managed clipboard buffer and no longer depends on the source program. The program can provide several different formats – e.g. text copied from MS Word can come in HTML, RTF, and plaintext formats simultaneously.



    (However, the program may store 'null' data and defer conversion until a paste is requested using WM_RENDERFORMAT. In this case data is lost when the program is closed. I'm not sure how common this method is.)



  • Ctrl+V tells the program to choose the desired format and retrieve it using GetClipboardData(). Some programs, e.g. WordPad or Paint, have a "Paste as" feature that lets you choose the preferred format (e.g. if you copied HTML but don't want formatting).


  • See also "NT Debugging: How the clipboard works" blog post.


In Linux, there is no system-wide clipboard, instead it is provided by whatever graphical environment you're using (that is, X11, Wayland, none):



In X11 (not necessarily limited to Linux), clipboard transfer is deferred. That is, the storage is provided by the 'source' program. The exchange is done via X11 messages according to the ICCCM protocol (therefore the clipboard is isolated to the X server):




  • Ctrl+C tells the source program to reserve the "copied" data in its own memory, and to claim the X11 selection called 'CLIPBOARD'. This is done using XSetSelectionOwner(), and the ownership is tracked by the X server (Xorg).



    If you had copied something previously, the previous selection owner is informed about this and discards the now-unneeded data.



    If you close the program, the copied data is lost. (Clipboard managers can be used to avoid this by watching and duplicating the current selection.)



  • Ctrl+V tells the destination program to look up the current owner of the 'CLIPBOARD' selection using XGetSelectionOwner(), then directly asks it for the preferred type using XConvertSelection(). The source program then returns the data via another X11 message, converted on-demand to the type that was requested. (There is also a special type which returns a list of possible types.)


  • See this link for a practical example.


(Note: When you "copy" text by selecting it and paste it using middle-click, the mechanism is the same but the 'PRIMARY' selection is used instead. This is where the term 'X11 selection' comes from.)



In Wayland – I don't actually understand how it works, all I have is the protocol docs:



  • https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-data-sharing


  • https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_data_device


  • See https://github.com/bugaevc/wl-clipboard for a command-line tool.


Traditional text editors (Vim, emacs, nano) often have their own internal clipboards (aka buffers/killrings). They might, or might not, also integrate with the X11 clipboard.



In macOS, something called a "pasteboard server" appears to be used (which I think means that programs communicate with it through Mach APIs). Other than that, it behaves like the Windows clipboard and stores the currently copied data itself.



  • https://developer.apple.com/documentation/appkit/nspasteboard


  • There is a sample application: https://developer.apple.com/library/archive/samplecode/ClipboardViewer/Introduction/Intro.html



I'm more intrigued with images, how can they be copied so easily




Images are just chunks of binary data, like text or audio. The clipboard will usually hold an image in formats common to the OS, e.g. BMP on Windows, image/png on Linux.



And on Linux, the X11 clipboard protocol actually allows one X client to offer different "encodings" of the selection to other clients, and the receiving X client can choose the encoding, so the sending X client gets to convert the selection into whatever format both clients understand. At least in theory; not sure if modern toolkit libraries like GTK or Qt do offer much choice.






share|improve this answer















In Windows, the clipboard API and storage buffer are provided by the OS at kernel level. (The clipboard belongs to the "window station" kernel object.)




  • Ctrl+C tells the program to store the "copied" data using the Win32 API function SetClipboardData(), which also corresponds to NtUserSetClipboardData() in the Native API.



    Normally, the copied data is immediately stored in the OS-managed clipboard buffer and no longer depends on the source program. The program can provide several different formats – e.g. text copied from MS Word can come in HTML, RTF, and plaintext formats simultaneously.



    (However, the program may store 'null' data and defer conversion until a paste is requested using WM_RENDERFORMAT. In this case data is lost when the program is closed. I'm not sure how common this method is.)



  • Ctrl+V tells the program to choose the desired format and retrieve it using GetClipboardData(). Some programs, e.g. WordPad or Paint, have a "Paste as" feature that lets you choose the preferred format (e.g. if you copied HTML but don't want formatting).


  • See also "NT Debugging: How the clipboard works" blog post.


In Linux, there is no system-wide clipboard, instead it is provided by whatever graphical environment you're using (that is, X11, Wayland, none):



In X11 (not necessarily limited to Linux), clipboard transfer is deferred. That is, the storage is provided by the 'source' program. The exchange is done via X11 messages according to the ICCCM protocol (therefore the clipboard is isolated to the X server):




  • Ctrl+C tells the source program to reserve the "copied" data in its own memory, and to claim the X11 selection called 'CLIPBOARD'. This is done using XSetSelectionOwner(), and the ownership is tracked by the X server (Xorg).



    If you had copied something previously, the previous selection owner is informed about this and discards the now-unneeded data.



    If you close the program, the copied data is lost. (Clipboard managers can be used to avoid this by watching and duplicating the current selection.)



  • Ctrl+V tells the destination program to look up the current owner of the 'CLIPBOARD' selection using XGetSelectionOwner(), then directly asks it for the preferred type using XConvertSelection(). The source program then returns the data via another X11 message, converted on-demand to the type that was requested. (There is also a special type which returns a list of possible types.)


  • See this link for a practical example.


(Note: When you "copy" text by selecting it and paste it using middle-click, the mechanism is the same but the 'PRIMARY' selection is used instead. This is where the term 'X11 selection' comes from.)



In Wayland – I don't actually understand how it works, all I have is the protocol docs:



  • https://wayland.freedesktop.org/docs/html/ch04.html#sect-Protocol-data-sharing


  • https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_data_device


  • See https://github.com/bugaevc/wl-clipboard for a command-line tool.


Traditional text editors (Vim, emacs, nano) often have their own internal clipboards (aka buffers/killrings). They might, or might not, also integrate with the X11 clipboard.



In macOS, something called a "pasteboard server" appears to be used (which I think means that programs communicate with it through Mach APIs). Other than that, it behaves like the Windows clipboard and stores the currently copied data itself.



  • https://developer.apple.com/documentation/appkit/nspasteboard


  • There is a sample application: https://developer.apple.com/library/archive/samplecode/ClipboardViewer/Introduction/Intro.html



I'm more intrigued with images, how can they be copied so easily




Images are just chunks of binary data, like text or audio. The clipboard will usually hold an image in formats common to the OS, e.g. BMP on Windows, image/png on Linux.



And on Linux, the X11 clipboard protocol actually allows one X client to offer different "encodings" of the selection to other clients, and the receiving X client can choose the encoding, so the sending X client gets to convert the selection into whatever format both clients understand. At least in theory; not sure if modern toolkit libraries like GTK or Qt do offer much choice.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 15 at 23:50


























community wiki





10 revs, 4 users 86%
grawity








  • 1





    Do X11 clipboard managers request all the available formats when they steal ownership from the original owner?

    – Ruslan
    May 14 at 15:57







  • 3





    Re: I'm not sure how common this method is, I have only ever noticed it in Word, Powerpoint and Publisher (suggesting that perhaps only Microsoft ever bothers to implement it). When you click close on the application, it asks if you wish to save the clipboard. I've only seen it happen when there's a large (>1MB) image on the clipboard.

    – Tim
    May 14 at 22:36






  • 10





    @AndrewSavinykh Technically these keyboard shortcuts must be interpreted by the specific application which must then call the appropriate API to fetch the data. But most applications rely on standard frameworks which provide widgets that implement these "standard" keyboard shortcuts, e.g. the basic Win32 Edit Control implements its own handling for Ctrl+C/Ctrl+V. So: applications that draw "from scratch" must implement shortcut handling, while applications that use existing frameworks often get it "for free".

    – Bob
    May 15 at 1:02







  • 3





    Also note, that in Linux, CTRL+C does not necessarily copy a text. In text terminals, which also holds for terminals in GUIs, CTRL+C usually treated as terminating the currently running process.

    – rexkogitans
    May 15 at 6:01







  • 2





    @ErinB: That very much depends on what type is common between the two programs... there is nothing that would stop e.g. a video editor from including all frames in its own format, but usually it'll only be understood by that same program, everyone else must resort to pasting generic single-frame formats. Same goes for MS Office data, for example.

    – grawity
    May 15 at 16:58












  • 1





    Do X11 clipboard managers request all the available formats when they steal ownership from the original owner?

    – Ruslan
    May 14 at 15:57







  • 3





    Re: I'm not sure how common this method is, I have only ever noticed it in Word, Powerpoint and Publisher (suggesting that perhaps only Microsoft ever bothers to implement it). When you click close on the application, it asks if you wish to save the clipboard. I've only seen it happen when there's a large (>1MB) image on the clipboard.

    – Tim
    May 14 at 22:36






  • 10





    @AndrewSavinykh Technically these keyboard shortcuts must be interpreted by the specific application which must then call the appropriate API to fetch the data. But most applications rely on standard frameworks which provide widgets that implement these "standard" keyboard shortcuts, e.g. the basic Win32 Edit Control implements its own handling for Ctrl+C/Ctrl+V. So: applications that draw "from scratch" must implement shortcut handling, while applications that use existing frameworks often get it "for free".

    – Bob
    May 15 at 1:02







  • 3





    Also note, that in Linux, CTRL+C does not necessarily copy a text. In text terminals, which also holds for terminals in GUIs, CTRL+C usually treated as terminating the currently running process.

    – rexkogitans
    May 15 at 6:01







  • 2





    @ErinB: That very much depends on what type is common between the two programs... there is nothing that would stop e.g. a video editor from including all frames in its own format, but usually it'll only be understood by that same program, everyone else must resort to pasting generic single-frame formats. Same goes for MS Office data, for example.

    – grawity
    May 15 at 16:58







1




1





Do X11 clipboard managers request all the available formats when they steal ownership from the original owner?

– Ruslan
May 14 at 15:57






Do X11 clipboard managers request all the available formats when they steal ownership from the original owner?

– Ruslan
May 14 at 15:57





3




3





Re: I'm not sure how common this method is, I have only ever noticed it in Word, Powerpoint and Publisher (suggesting that perhaps only Microsoft ever bothers to implement it). When you click close on the application, it asks if you wish to save the clipboard. I've only seen it happen when there's a large (>1MB) image on the clipboard.

– Tim
May 14 at 22:36





Re: I'm not sure how common this method is, I have only ever noticed it in Word, Powerpoint and Publisher (suggesting that perhaps only Microsoft ever bothers to implement it). When you click close on the application, it asks if you wish to save the clipboard. I've only seen it happen when there's a large (>1MB) image on the clipboard.

– Tim
May 14 at 22:36




10




10





@AndrewSavinykh Technically these keyboard shortcuts must be interpreted by the specific application which must then call the appropriate API to fetch the data. But most applications rely on standard frameworks which provide widgets that implement these "standard" keyboard shortcuts, e.g. the basic Win32 Edit Control implements its own handling for Ctrl+C/Ctrl+V. So: applications that draw "from scratch" must implement shortcut handling, while applications that use existing frameworks often get it "for free".

– Bob
May 15 at 1:02






@AndrewSavinykh Technically these keyboard shortcuts must be interpreted by the specific application which must then call the appropriate API to fetch the data. But most applications rely on standard frameworks which provide widgets that implement these "standard" keyboard shortcuts, e.g. the basic Win32 Edit Control implements its own handling for Ctrl+C/Ctrl+V. So: applications that draw "from scratch" must implement shortcut handling, while applications that use existing frameworks often get it "for free".

– Bob
May 15 at 1:02





3




3





Also note, that in Linux, CTRL+C does not necessarily copy a text. In text terminals, which also holds for terminals in GUIs, CTRL+C usually treated as terminating the currently running process.

– rexkogitans
May 15 at 6:01






Also note, that in Linux, CTRL+C does not necessarily copy a text. In text terminals, which also holds for terminals in GUIs, CTRL+C usually treated as terminating the currently running process.

– rexkogitans
May 15 at 6:01





2




2





@ErinB: That very much depends on what type is common between the two programs... there is nothing that would stop e.g. a video editor from including all frames in its own format, but usually it'll only be understood by that same program, everyone else must resort to pasting generic single-frame formats. Same goes for MS Office data, for example.

– grawity
May 15 at 16:58





@ErinB: That very much depends on what type is common between the two programs... there is nothing that would stop e.g. a video editor from including all frames in its own format, but usually it'll only be understood by that same program, everyone else must resort to pasting generic single-frame formats. Same goes for MS Office data, for example.

– grawity
May 15 at 16:58

















draft saved

draft discarded
















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1436622%2fhow-do-ctrlc-and-ctrlv-work%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020