|
-
Jun 3rd, 2008, 08:11 AM
#1
Thread Starter
Addicted Member
[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
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 6th, 2008, 01:08 PM
#2
Addicted Member
Re: [2008] Tracking Clipboard Paste
 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.
-
Jun 6th, 2008, 01:27 PM
#3
Re: [2008] Tracking Clipboard Paste
I'd recommend using the SetClipboardViewer API call....see this article for an example/explanation
-
Jun 6th, 2008, 02:04 PM
#4
Thread Starter
Addicted Member
Re: [2008] Tracking Clipboard Paste
 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?
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 6th, 2008, 02:11 PM
#5
Addicted Member
Re: [2008] Tracking Clipboard Paste
 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.
-
Jun 7th, 2008, 04:14 AM
#6
Thread Starter
Addicted Member
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
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 7th, 2008, 03:24 PM
#7
Addicted Member
Re: [2008] Tracking Clipboard Paste
 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
 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.
-
Jun 7th, 2008, 03:27 PM
#8
Addicted Member
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.
-
Jun 7th, 2008, 03:31 PM
#9
Addicted Member
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?
-
Jun 7th, 2008, 03:40 PM
#10
Thread Starter
Addicted Member
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 ?
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 7th, 2008, 08:34 PM
#11
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).
-
Jun 8th, 2008, 03:17 AM
#12
Thread Starter
Addicted Member
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 ?
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 8th, 2008, 02:39 PM
#13
Addicted Member
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.
-
Jun 8th, 2008, 03:06 PM
#14
Thread Starter
Addicted Member
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) ?
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 8th, 2008, 03:22 PM
#15
Addicted Member
Re: [2008] Tracking Clipboard Paste
 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.
-
Jun 8th, 2008, 03:28 PM
#16
Thread Starter
Addicted Member
Re: [2008] Tracking Clipboard Paste
this API would work?
RegisterHotKey(NULL, 666, MOD_CONTROL, 'V');
is this hooking or no ?
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 8th, 2008, 04:08 PM
#17
Addicted Member
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.
-
Jun 8th, 2008, 04:34 PM
#18
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jun 9th, 2008, 08:53 AM
#19
Thread Starter
Addicted Member
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
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 9th, 2008, 10:34 AM
#20
Thread Starter
Addicted Member
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
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Jun 9th, 2008, 06:18 PM
#21
Addicted Member
Re: [2008] Tracking Clipboard Paste
 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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|