Results 1 to 21 of 21

Thread: [2008] Tracking Clipboard Paste

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    [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

  2. #2
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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.

  3. #3
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: [2008] Tracking Clipboard Paste

    I'd recommend using the SetClipboardViewer API call....see this article for an example/explanation

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    Re: [2008] Tracking Clipboard Paste

    Quote Originally Posted by Merrion
    I'd recommend using the SetClipboardViewer API call....see this article for an example/explanation
    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

  5. #5
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    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

  7. #7
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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.

  8. #8
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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.

  9. #9
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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?

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    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

  11. #11
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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).
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    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

  13. #13
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    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

  15. #15
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    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

  17. #17
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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.

  18. #18
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    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

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    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

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    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

  21. #21
    Addicted Member joe1985's Avatar
    Join Date
    Jun 2007
    Posts
    151

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width