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

Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company