2

I have a windows desktop application in c# (WPF), which is basically an issue managing application for a call center. It manages (adds, edits, deletes,...) customer issues (records in database), where each issue has numerous fields (textboxes, textareas, checkboxes,...) While the issue is generated, a user often copies/pastes data from other resources to this and other applications (excel, notepad, browser...), and has a windows clipboard full of valuable data.

The problem i don't know how to solve is: A user selects a random text in any textfield (textbox for example) in this program, and copies the data. but this data can't be copied to the clasic windows clipboard

Clipboard.SetText(Textbox1.Text);

because clipboard already has a valuable data, that can't be lost. So i'd like to create a second clipboard which listens to all keyboard input. And whenever a certain combination of keys is pressed it reads the selected text (only text is needed), from any application (notepad, excel, my program,...). Similarly with another combination of keys it pastes that copied text to any application (notepad, excel,..)

Windows already has that functionaliy with the shortcuts CTRL+C and CTRL+V, which work in any application that doesn't override those shortcuts. I'd like to the same for my custom clipboard application/service, with different shortcuts. But i don't know how to get and paste the data to any textfield in any windows application. In a nutshell, i'd need something like:

string clipboardData;

public void OnSpecialCopyShortcutPressed() {
  clipboardData = SelectedTextAnywhereInWindowsOrAnyWindowsApp.Text;
}

public void OnSpecialPasteShortcutPressed() {
  focusedTextFieldAnywhereInWindowsOrAnyWindowsApp.Text = clipboardData;
}

Basicaly i'd like to have two windows clipboards.

Any pointers would be great. Thank you.

--- edit ---

found the solution for hooking up to the keys pressed here global keyboard hook Still looking for a way to "hook up" to active apps and selected text for copying and focused controls for pasting copied text.

Community
  • 1
  • 1
inbit
  • 21
  • 1
  • 4
  • 2
    Nobody is going to know how to use what you are proposing. On the other hand everyone understands the clipboard. Why don't you just use one of the many clipboard apps that remember a history of items in the clipboard. – David Heffernan Aug 23 '11 at 10:13
  • I proposed the same to my customer (an app that remembers history of items copied to clipboard), but he insists on having two clipboards. Usage would be fairly simple, just different keys for copy and paste than in regular keyboard. – inbit Aug 23 '11 at 17:45
  • Your customer has it all wrong, but the customer is always right! – David Heffernan Aug 23 '11 at 17:53
  • haha, good one with custumer is wrong, but always right. I don't have much experience in "backend windows" development to push data in window apps. But yes i assumed, it's quite difficult to paste data in various windows applications, unless those are designed in that manner. That's why i asked for help and other opinions. Thanks for the replies – inbit Aug 29 '11 at 10:46

3 Answers3

1

You can't have two windows clipboards. You can put something together that will act like a clipboard in certain situations, but it's not going to work for every app (or most apps). The best you could hope for is to capture text with hotkeys in the app that you have control of, and use sendkeys to type the data into other apps that are cooperative. Forget fancy formats like HTML, RTF, Bitmap.
I wrote the original windows clipboard extender (ClipMate) in 1991, so I've seen all sorts of ideas on how to improve the clipboard. This is one of the worst. I include this commentary not to poke fun at you or your client, but in hopes that you can use it to persuade your client from wasting lots of time and money on this boondoggle.

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62
  • Thanks for the comment. I did try to persuade my client into using already available "clipborad logger" such as "extended clipboard" or similar, instead of developing second clipboard. But i didn't/don't know if making a second clipboard is sensible or even possible. – inbit Aug 29 '11 at 10:50
  • No argument against having two clipboards was raised. It's a valid strategy. See http://stackoverflow.com/questions/9658282/javascript-cut-copy-paste-to-clipboard-how-did-google-solve-it?rq=1 ref google and what they did. – servermanfail Mar 16 '14 at 10:14
0

There are several optiosn to share data between applications: IPC
Memory mapped file
File on filesystem
Using the network via localhost.

Have you explorered these options?

Perhaps read up this article?

EKS
  • 5,543
  • 6
  • 44
  • 60
0

What I would do in a situation like this is:

  1. Create a service named 'MyClipBoard' or whatever.
  2. Create global keyboard hooks to look for whatever key combinations you are trying to look. i.e., Alternatives of Ctrl + C and Ctrl + V
  3. Whenever you encounter a key combination meant for copying, look for the active window and then get the selection from that window.
  4. Copy the selection to a memory area in your 'MyClipBoard'.
  5. When you encounter keyboard pasting combination, paste the data in your clipboard to the activewindow's focussed window.

This all requries a good knowledge of Keyboard hooks and Windows APIs. And this may not be the perfect solution either.

The most important question is: Why do you want to do this? This doesn't seem to be a correct way of tackling the problem.

Aamir
  • 14,882
  • 6
  • 45
  • 69
  • Somewhat over the top and it doesn't work anyway. CTRL+C is far from the only way to get text into the clipboard. – David Heffernan Aug 23 '11 at 10:09
  • Yes that's pretty much what i'm trying to do. I just don't know how to get an active window and selected text, outside of current application/service. And likewise don't know hot to get the active windows focused text box outside the current application/service to paste the data. The process of using this application is: a customer calls, user of the program saves customers phone number to the clipboard. browses for another data(text) on the web, which also needs to be copied to this program. but clipboard is already filled with phone number which can't be lost... – inbit Aug 23 '11 at 10:16