1

I want to make a simple windows32 console application using c++ that takes what is stored in the CTRL+C buffer and copies it in a char array or a string.

Example: I select the word "Hello", I press CTRL+C and then the program put the word "Hello" (stored in the buffer) in a char array.

  • 1
    Splendid idea?? Was there a *question*? Or were you just looking for a link to the [Windows Clipboard API](http://msdn.microsoft.com/en-us/library/windows/desktop/ff468801(v=vs.85).aspx)? – WhozCraig May 25 '14 at 12:20
  • @JoachimPileborg I don't know if you are kidding, but I think the OP wants to copy the text that is on the clipboard. – Massa May 25 '14 at 12:21
  • Yes @Massa, exactly what you told. – GianSegugio May 25 '14 at 22:14

1 Answers1

0

One problem is that CTRL-C is not sent as a normal keystroke like most other CTRL-key combinations, that's because CTRL-C is the break signal and is handled specially by the console to send a special break signal to your application, and if your application doesn't handle it then it will be terminated. Another problem is that input from the console is normally line-based, and you only get input once the user has pressed the newline or Enter key.

A possible solution for the first problem is to use the SetConsoleCtrlHandler function to set a handler function to catch the signal, and in the handler tell the application that CTRL-C has been pressed.

A solution for the both problems is to change the console mode to not process CTRL-C, and to disable the line based input.

Also note that normally CTRL-C is used to copy selected content to the clipboard and not from, which is usually CTRL-V.


But handling of the keystrokes is only a small part of the problem, as you then have to work with the clipboard for the actual copy-pasting.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621