[2008] Tracking Clipboard Paste
I want to track the windows clipboard paste,
here is an example of I want to do:
Lets say we have 5 strings, we save the first string in clipboard, I want to paste this string only once, when the string is pasted anywhere, I want to save the next string in the clipboard (get rid of the first string)...
so a way to do this would be to hook GetClipboardData and then in the hook function use EmptyClipboard and then SetClipboardData to put the next string in the clipboard...
the problem is I can't find how to hook the GetClipboardData, all the tut and code hook the entire keyboard, I would be thankful if someone can help me hook the GetClipboardData or show me a better way to do this...
Thanks
Re: [2008] Tracking Clipboard Paste
Quote:
Originally Posted by perito
I want to track the windows clipboard paste,
here is an example of I want to do:
Lets say we have 5 strings, we save the first string in clipboard, I want to paste this string only once, when the string is pasted anywhere, I want to save the next string in the clipboard (get rid of the first string)...
so a way to do this would be to hook GetClipboardData and then in the hook function use EmptyClipboard and then SetClipboardData to put the next string in the clipboard...
the problem is I can't find how to hook the GetClipboardData, all the tut and code hook the entire keyboard, I would be thankful if someone can help me hook the GetClipboardData or show me a better way to do this...
Thanks
You need to use SetWindowsHookEx
http://msdn.microsoft.com/en-us/library/ms644990.aspx
Then you can set a hook for the specific message.
Re: [2008] Tracking Clipboard Paste
I'd recommend using the SetClipboardViewer API call....see this article for an example/explanation
Re: [2008] Tracking Clipboard Paste
Quote:
Originally Posted by Merrion
I tried that API, it only fires when the clipboard changes, not when the clipboard is pasted ... unless I'm doing something wrong ... right?
Re: [2008] Tracking Clipboard Paste
Quote:
Originally Posted by perito
I tried that API, it only fires when the clipboard changes, not when the clipboard is pasted ... unless I'm doing something wrong ... right?
No you are not doing anything wrong
"The SetClipboardViewer function adds the specified window to the chain of clipboard viewers. Clipboard viewer windows receive a WM_DRAWCLIPBOARD message whenever the content of the clipboard changes."
You need to set a global hook for the message WM_PASTE.
Re: [2008] Tracking Clipboard Paste
I can't find any example on how to hook the WM_PASTE message ... can anyone help me with that or atleast till me where should I look, because I really don't know to get this hook working ...
Thanks all
Re: [2008] Tracking Clipboard Paste
Quote:
Originally Posted by perito
I can't find any example on how to hook the WM_PASTE message ... can anyone help me with that or atleast till me where should I look, because I really don't know to get this hook working ...
Thanks all
Well, I did search for a few hours last night for you and I wasn't able to find anything. I did write code that monitored a specific textbox, but I wasn't able to apply that globally. Then I found this article
http://support.microsoft.com/kb/318804
At the very bottom it says
Quote:
Originally Posted by Microsoft
Global hooks are not supported in the .NET Framework
Except for the WH_KEYBOARD_LL low-level hook and the WH_MOUSE_LL low-level hook, you cannot implement global hooks in the Microsoft .NET Framework. To install a global hook, a hook must have a native DLL export to inject itself in another process that requires a valid, consistent function to call into. This behavior requires a DLL export. The .NET Framework does not support DLL exports. Managed code has no concept of a consistent value for a function pointer because these function pointers are proxies that are built dynamically.
Low-level hook procedures are called on the thread that installed the hook. Low-level hooks do not require that the hook procedure be implemented in a DLL.
Re: [2008] Tracking Clipboard Paste
That being the case you can set a hook for WM_PASTE for specific handles of controls but not globally in .NET from what I understand. I was able to set WM_PASTE hook for a text box on a form, but that doesn't really seem to fit the bill for you.
So you've got a couple options
1. You could set a global hook for the key combination CTRL+V
or
2. You could write a hook DLL unmanaged code and add it as a reference to your application.
The first option would be easier but wouldn't necessarily confirm that the Paste command was sent.
Re: [2008] Tracking Clipboard Paste
What is the reason you are wanting to track copy and paste commands?
Maybe there is something that might be more efficient for what you are trying to accomplish.
What is is the intended purpose?
Re: [2008] Tracking Clipboard Paste
here is what I want to do:
I have to write 10 strings in the fastest possible time, so I thought the fastest way is to write the strings before the timer is triggered and simply paste them all (each time I paste a string, the program will put in the clipboard the next string) that will save me MUCH time (and every quarter of a second does count...)
anyway, the Ctrl + V is enough, do you know how I can do that ?
Re: [2008] Tracking Clipboard Paste
Do you have source codes of both programs ? The Text Sender and the Text Receiver ?
If yes, you can simply use IPC (Internet Process Communication).
Re: [2008] Tracking Clipboard Paste
no, the strings will be written on a website testbox... the only option is the paste command...
so how can I track the Ctrl+V command ?
Re: [2008] Tracking Clipboard Paste
Register it as a hot key. There is an API and tons of information on google and these forums about it.
Re: [2008] Tracking Clipboard Paste
eh doesnt registering it as a hotkey remove its original function (ie: it wont paste after registering it as hotkey) ?
Re: [2008] Tracking Clipboard Paste
Quote:
Originally Posted by perito
eh doesnt registering it as a hotkey remove its original function (ie: it wont paste after registering it as hotkey) ?
Not unless you hook it and don't pass the message on once you've received it.
Re: [2008] Tracking Clipboard Paste
this API would work?
RegisterHotKey(NULL, 666, MOD_CONTROL, 'V');
is this hooking or no ?
Re: [2008] Tracking Clipboard Paste
Yes, if you implement it correctly. I would say to look for hot key examples on google or this forum.
Re: [2008] Tracking Clipboard Paste
try the hotkeys link in my signature.
but you should try to hook the WM_PASTE msg. CTRL+V won't catch all pasting
Re: [2008] Tracking Clipboard Paste
thanks for the code, i'll check it out now
can u guys help me here:
http://www.vbforums.com/showthread.php?t=526355
Re: [2008] Tracking Clipboard Paste
@.paul.
ur hotkeys program removes the original function of the hotkey, for example, if I did Ctrl + V, it doesnt paste anymore, how to keep it doing its function ?
and your program doesnt show how to Register TAB as a hotkey
Re: [2008] Tracking Clipboard Paste
Quote:
Originally Posted by perito
here is what I want to do:
I have to write 10 strings in the fastest possible time, so I thought the fastest way is to write the strings before the timer is triggered and simply paste them all (each time I paste a string, the program will put in the clipboard the next string) that will save me MUCH time (and every quarter of a second does count...)
anyway, the Ctrl + V is enough, do you know how I can do that ?
I am reviewing the Ctrl + V issue you are experiencing with the hot keys.
May I ask, why you don't just use send keys?