Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS independent clipboard copy/paste text in C

Tags:

c

clipboard

I'm working on a project that's supposed to work on both Windows and Linux (with an unofficial Mac port as well) that emulates a true colour system console.

My problem is that recently there appeared a request for textfield support (yes, console-based) and it would be cool to add the possibility of copying text to clipboard and pasting from it. Is there a way of achieving this that will:

  • be done in C (not C++),
  • work in both Windows and in Linux (preprocessor macros are an option if there's no platform-independent code),
  • require no extra libraries to link to?

Thanks in advance for your help.

like image 677
mingos Avatar asked Feb 16 '10 02:02

mingos


People also ask

How do I copy and paste from clipboard to Vim?

When using Vim under Windows, the clipboard can be accessed with the following: In step 4, press Shift+Delete to cut or Ctrl+Insert to copy. In step 6, press Shift+Insert to paste.

How do I copy text from clipboard to Vi?

You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.

How do you copy and paste on a virtual machine?

Right-click and select Copy, or press Ctrl+C to copy the text. In the VM, click where you want to paste the text. Press Ctrl+V.


2 Answers

If you're not using a cross platform UI library (like wx or something), then it sounds like you're just going to have to write native clipboard code for each platform you want to support.

Remember, on Macintoshes, you copy with Command-C, not Ctrl+C :)

like image 89
Seth Avatar answered Oct 23 '22 16:10

Seth


The clipboard is inherently an operating system defined concept. The C language itself has no knowledge of what a clipboard is or how to operate on it. You must either interface directly with the OS, or use a portability library that does this on your behalf. There is no way around this.

like image 23
Tyler McHenry Avatar answered Oct 23 '22 15:10

Tyler McHenry