I've been reading about ApplicationCommands (specifically Paste) here and I have a question regarding the following paragraph:

A MenuItem is created and it's Command property is set to the Paste command. The CommandTarget is not explicitly set to the TextBox object. When the CommandTarget is not set, the target for the command is the element which has keyboard focus. If the element which has keyboard focus does not support the Paste command or cannot currently execute the paste command (the clipboard is empty, for example) then the MenuItem would be grayed out.

I understand in general what the sentence in bold means, and how it applies to the application I'd be creating myself. However, is it possible that the target for the command be an element (that has keyboard focus etc.) in a different application?

The specific thing I'm thinking of here is a background process that listens for an event (I'm thinking a HotKey or similar) and then pastes text into whatever currently has keyboard focus. For now it would just be the same text every time, so I wouldn't need to paste something specific to whatever happens to have focus (if such a thing is even possible).

I haven't started on anything yet, it was just an idea I came up with and am interested in investigating.

Thanks for any help!

It means exactly that. As long as what has focus can accept a paste and there is something to paste, it will work just like when you copied that text from the webpage where you found it and pasted it into the box to post your message :)

Hi there,
You will need to listen to all the windows messages and find the one(s) you want.
If it is a paste command then you might need to capture the event - copy what ever you need into the clipboard then let the original target app pick up the message aswell. I looked at capturing these type of messages along time ago and do not remember the details.

A nice example of capturing the messages can be found:
http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx

Hope this helps.

N

Thank you both for getting back on my first question. I've now started building my app and have made some good progress, but have run into another issue.

I've created a custom command that will be called when the appropriate key binding event has been raised so that I can process the information needed before pasting it (which is my final goal). I could tie the command to any other control in my app, a button for example, and learned how to do so. However, what I want to do is after I've processed the information I now need to call the ApplicationCommands.Paste command, but I don't have a control/binding/etc. to tie it to. So as soon as I'm done processing in my command that's called after the key binding is raised, I want to call another command. Is there any way to do that? I've searched around quite a bit, but all I could find is information on how to tie commands to controls etc, but not how to just call one on its own.

Is this perhaps what you had mentioned N4JRY? That I would have to have the key binding call the AppCommands.Paste command and intercept it in order to do some processing before the paste actually completes? It seems like there should be a way to just call a command... but I can't seem to find one.

Thanks for your help!
-Oredigger

This is not exactly what I had to do but if I have understood you correctly then you could raise a new windows message that the second application can capture and interpret.
Have a read of this article. It may give you what you need:
http://ryanfarley.com/blog/archive/2004/05/10/605.aspx

N

commented: Interesting sig. +11

I may not have understood everything in that article correctly, but it seemed like it detailed how to send messages between two applications that I would have control of (ie, two apps that I wrote) since you have to have a specific target process to send the message to:

//now send the RF_TESTMESSAGE to the running instance
SendMessage(p.MainWindowHandle, RF_TESTMESSAGE, IntPtr.Zero, IntPtr.Zero);

What I'm looking for is a way to send a message (specifically a Paste command) but not give the process to send it to... This is assuming I guess that the OS can route the command to whatever window has focus, and then what has focus can accept a Paste command.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.