Hacker News new | ask | show | jobs
by dragontamer 1476 days ago
There was a browser based game called "Utopia" in the 00s that was reasonably popular. Someone wrote a tool where you'd copy/paste your kingdom homescreen, and get all sorts of calculations / predictions.

It was one of the easiest-to-use calculators I've ever seen. Just enter your webpage to play the game, Ctrl-A (select-all), Ctrl-C (copy), and bam, the Utopia-program would instantly analyze your kingdom and provide advice.

Just all off of the HTML-copy that Clipboard supports.

------------

Windows developers "know" the clipboard is one of the most important inter-process communication structures of the entire system, and have known for years. Its probably one of the Win32 API's biggest advantages, no joke.

The shear amount of creative solutions I've seen from clipboard manipulations is outstanding.

1 comments

Since Windows 7 or so, I've noticed more and more instances where you ctrl+C and the clipboard doesn't update. I had a chat with a Windows PM on it opportunistically a while back.

It turns out, more and more applications are locking the clipboard and holding onto the lock inappropriately. Enough that there's a particular telemetry watcher for this condition for MSFT to get an idea on who the guilty parties are.

Everyone has had it happen - I notice it when colleagues are in a rush and send me something they didn't mean to send (because their clipboard didn't update). I don't know who the guilty parties are (since that telemetry is encrypted, and can't be inspected), but I sure hope someone is knocking down some doors to address the problem.

Coming from the other side, most apps don't check the winapi error code when copying text. One app I use (notepad2 maybe?) at least throws up a tiny "Error" dialog box when it fails.

I configured my clipboard manager to make a crinkly paper noise when an app copies, so at least I have some feedback when it fails.

Oooh so that's what that is. I've had it happen numerous times where I was absolutely sure I pressed CTRL+C yet the clipboard was empty. I now use CTRL+X and CTRL+Z just because of that.
That's interesting - that Ctrl+X behaves differently. It shouldn't right?

But you have found that it helps?

It helps because there is visual feedback so you're sure you don't have to go back to the original program and do the copy again. Plus sometimes your original program forgets your selection, with CTRL+X you're sure it's on the clipboard and won't have to return.
A weird one I've noticed with the clipboard on the Mac, is that the "rich text" clipboard and the "plain text" one seem to be able to get out of sync. This is most noticeable to me when trying to paste text into some dialog boxes in Microsoft Word.
This sounds to me like it's probably a proxy for the rise of GC languages. C#, which I reference because it's popular for windows desktop apps, has IDisposable and using() which helps a lot, but isn't mandatory. If you don't do something like this and there isn't memory pressure, there are low odds of a handle or resource lock being released.
This must be a common issue because now that you say it I realized that I have a habit of always Ctrl-C'ing multiple times. Could also be the keyboard, most of mine had a glass of Coke at some point in time.
One guilty party: some versions of the RealVNC client randomly lock the clipboard.
Genuine question, why is it even possible to lock the clip board?
An application doing a paste needs to query the available clipboard formats and then ask for the data from one of them. This wouldn't work reliably if other applications could simultaneously change the clipboard. So the OpenClipboard API locks the clipboard and applications need to remember to call CloseClipboard.
I have tried to track this down - it seems like at some point it was not possible. My guess is Vista is when the lock was implemented. I've come up blank repeatedly.

I am sure Raymond Chen knows. Looks like comments are allowed on his blog too!