The example (1) provides a working code snippet, (2) detects when a user enters the form input, and triggers automatic selection of the complete code snippet, and (3) if your (visitor's) browser supports it1 automatically copies that selected text into the clipboard buffer in order to make it available for pasting (CTRL-V in windows).
Try it out below:
Copy this code to play hangman from your own site:
Paste sample code here:
HTML Rendering of Sample code above
(waiting for HTML in sample input)
1 - Your visitor's browser must support the clipboardData2 object in order to automatically copy the highlighted text into the clipboard. This object is supported by Internet Explorer, and not much else. Anecdotally this could be 80% or more of your traffic if your visitation mirrors general Internet trends. If however, you are part of the non-IE crowd (lets face it, us web developers, our friends and family who's security we care about, and various other non-conformists and hobbyists ;-) then this means you'll have to manually copy to the buffer using CTRL-C, or right-clicking the highlighted text and selecting "Copy" from the context-menu that appears there.
2 - You can find more information about the clipboardData object here, http://msdn.microsoft.com/en-us/library/ms535220%28VS.85%29.aspx.
3 - If you want to explore an alternative that supports the copy to buffer functionality using a flash-based technique, here is a site which describes such a technique, http://www.jeffothy.com/weblog/clipboard-copy/.
the clipboard and uses it if available.