views:

49

answers:

1

Hello all,

I am working on a project which aims to gather data on students' writing styles. One issue we are currently facing is the idea of context menus. Is there a way I can be notified when the user right clicks, and then clicks "copy," "paste," or any other option?

Thanks, Emily

A: 

I'm not sure I agree with your intended approach, but you might want to look into this article on Customizing Context Menus in Office.

If you were to remove all existing context menu offerings and provide your own which wrap those offerings, you can effectively hook into those commands as they're being executed.

That said, I'd like to ask what problem you're trying to solve with this approach; perhaps there's another way?

Randolpho
I would like to be notified when the user performs a cut/copy/paste operation, and this seemed to be a simpler solution than global hooks. I guess it might not be. If you have another way to track when a user does this, I'd love to know.
zipzapzop
What about ctrl-c and ctrl v? what about the menu on top *edit*->*paste*
masfenix
@zipzapzop: this sounds like it's a lot more complex than it needs to be. Again I ask: what problem are you attempting to solve with this approach? Perhaps there's another way.
Randolpho
@masfenix -- Already took care of the ctrl-c, -v, -x stuff. That was simple.@Randolpho -- A university would like to gather information on its freshman student writing classes. They will know that they are being monitored. Currently, the program logs keystrokes, mouse movements, and what I mentioned to masfenix, but they would like to see the program track whenever the user performs a cut, copy, or paste operation. This would benefit their research and provide data for long-held assumptions about writing.
zipzapzop
I thought that since I already am tracking ctrl x/c/v, tracking when a user clicks "copy," etc from a menu would exhaust the possible ways of performing these operations. Hooking the global events has been a problem for me, so I have been pursuing this method.
zipzapzop
@zipzapzop: Interesting scenario. I withdraw my disagreement to your approach. :) That said, I think global events might be a better alternative; have you tried using [`SetClipboardViewer`](http://msdn.microsoft.com/en-us/library/ms649052.aspx) yet? Here's a nice article on how to [create a clipboard monitor in C#](http://www.radsoftware.com.au/articles/clipboardmonitor.aspx).
Randolpho
@Randolpho -- Thanks for discussing this with me. It's very helpful :)I have seen those examples, but the C# example only notifies me when a cut/copy has taken place. It cannot distinguish between the two, and is incapable of tracking "paste" operations. I haven't tried the VB example yet -- thank you. I'll post again once I try that.
zipzapzop
Also, I was under the impression that you couldn't hook global events in C#, with a few low-level exceptions.
zipzapzop
@zipzapzop: you can do a lot with c#. In this case, you'll have to use Win32 interop and call the native win32 binaries from C#. Or you could do it in C/C++. I just added that link because you have C# tagged on your question.
Randolpho