How to get URL of clipboard text?

Poloboc
Posts: 2
Joined: Thu Jun 23, 2011 12:05 pm
Contact:

How to get URL of clipboard text?

Postby Poloboc » Thu Jun 23, 2011 12:12 pm

Hello!

I'd like to implement a feature similar to the one in CintaNotes in a project of mine:

Clip text from anywhere. Just select it and press the hotkey!
The text-clipping "magic" works in any application that can copy text to clipboard. CintaNotes automatically saves the text and its source URL, and you don't even have to install a plug-in to integrate it with your web browser!


How do you do this programmatically? (Preferably C#, but I guess I can use PInvoke..)

Thanks.

Edit: did some more digging.. is this it? http://msdn.microsoft.com/en-us/library/aa767917%28VS.85%29.aspx
The source url is always included in the base tag of the clipboard data when you copy a selection from a page in a web browser?
User avatar
CintaNotes Developer
Site Admin
Posts: 5002
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: How to get URL of clipboard text?

Postby CintaNotes Developer » Fri Jun 24, 2011 4:23 am

The main principle is as following: on a hot key CN emulates pressing
Ctrl+C and then examines clipboard. This gets the note's text into CN.
To fill the Link field, in the CF_HTML clipboard data there's indeed a field
SourceURL that contains the page URL, but unfortunately not all
browsers fill out this field (Opera, I'm looking at you ;) )

This is where "Plan B" kicks in. CN sees that there's no URL, but
the program is the browser. So depending on a browser, it sends a
series of keystrokes to focus the address bar, select everything there
and copy it to clipboard.

APIs used:
OpenClipboard
RegisterClipboardFormat
GetClipboardOwner
GetClipboardData
IsClipboardFormatAvailable
EmptyClipboard
SetClipboardData
CloseClipboard
FindWindowEx
GetForegroundWindow
keybd_event
GetWindowThreadProcessId
AttachThreadInput
GetCurrentThreadId
OpenProcess


These are the main points. Hope this helps!!
Alex
Poloboc
Posts: 2
Joined: Thu Jun 23, 2011 12:05 pm
Contact:

Re: How to get URL of clipboard text?

Postby Poloboc » Sat Jun 25, 2011 11:54 am

Thanks!

I did check to see if SourceURL exists for Chrome, Firefox and IE. Guess I forgot Opera. But everyone seems to forget Opera these days :)
Kelden

Re: How to get URL of clipboard text?

Postby Kelden » Wed Jun 29, 2011 9:21 am

CTRL+C is evil. I did the same before. Use IUI­Automation­Text­Pattern.

Check this page:

What happens when applications try to copy text by sending Ctrl+C
http://blogs.msdn.com/b/oldnewthing/arc ... 78000.aspx
User avatar
CintaNotes Developer
Site Admin
Posts: 5002
Joined: Fri Dec 12, 2008 4:45 pm
Contact:

Re: How to get URL of clipboard text?

Postby CintaNotes Developer » Thu Jun 30, 2011 4:14 am

Thanks for the comment, Kelden!
The main question for me here is then, do all the apps support the IUI­Automation­Text­Pattern interface?
Alex

Return to “CintaNotes Personal Notes Manager”