Click here to Skip to main content
13,000,179 members (72,851 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 23 Oct 2007

Clipboard little helper

, 4 Nov 2007
Rate this:
Please Sign up or sign in to vote.
Clipboard little helper - manage your clipboard the easiest way.

Screenshot - 1.png


This is a small utility I found myself missing when I needed to copy/paste several phrases/words several times. It scans the Windows Clipboard for new items, puts them in the list, and when the user presses Ctrl+Shift+V, it displays a window with the list of those items. The tricky thing is that it listens for those keys being pressed in any window. After the user clicks an item he wants to use, it's pasted into the active form in a text box or a writing area.

The most important thing is that when you want to paste some text you have previously put in the Clipboard, all you have to do is select the destination text box in any window (one exception I found is text boxes in Flash animations) - text editor, web browser etc. - press Ctrl+shift+V, and click on the desired item; after releasing the left mouse key, the selected text is pasted - in just three moves!!!

Using the code


The Clipboard is maintained by the ClipboardListener class, which has two public functions:

  • GetClipboardText
  • SetClipboardText

I started with the .NET functions for accessing the Clipboard, but after several problems concerning the usage of those functions, I took a peek at the Windows API, and used them with success. Those functions are:

  • OpenClipboard
  • EmptyClipboard
  • GetClipboardData
  • SetClipboardData
  • CloseClipboard

I used several others functions from the Windows API - mostly for memory access, but I'm not going to mention them here.

Handling keyboard

Checking for key-combinations is done by using a keyboard hook. The Keyboard class listens for pressed/released keys, and when certain combinations are pressed, it fires. Keyboard hooks are described in detail in several articles on this site (I have read them :-)), so please use the Search feature for more information. Just look for the Windows API functions:

  • SetWindowsHookEx
  • UnhookWindowsHookEx
  • CallNextHookEx

Pasting contents

To paste certain text into the desired place, the program simulates keyboard actions - it copies text into the Clipboard using the ClipboardListener class, and "presses" Ctrl+V using the Windows API function keybd_event:

//press Ctrl
keybd_event(VK_CONTROL, 0, 0, 0);
//press V
keybd_event((byte)VkKeyScan((byte)'v'), 0, 0, 0);
//release Ctrl
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
//release V
keybd_event((byte)VkKeyScan((byte)'v'), 0, KEYEVENTF_KEYUP, 0);

keybd_event sends a message to the active window. But what window shall we send to - we need a handle. All we know is that the destination window is on the top before the window with the list is displayed. For that task, I used several other Windows API functions:

  • EnumWindows
  • GetWindowModuleFileName
  • IsWindowVisible

EnumWindows fills the list with handles for windows, but with a certain order - from the topmost window to the very bottom. All I had to do was reject the hidden windows and return the second window from the list (first was the window with the list).

After acquiring the handle, I set the focus for that window, the cursor is brought to the previous position, and the window receives the messages for "Ctrl+V" - and text is pasted in place. To set the focus, I used the Windows API functions:

  • SetForegroundWindow
  • SetFocus

Last will

This is my first article, so please be kind :-)


  • 2007.11.05 - activates window with the list with mouse-left-key-click as well; puts the most recent items at the top of the list.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Poland Poland
Studying Computer Science at Warsaw University of Technology, working application and code review, and programming for myself since 9 years. Also great fan of advertising, especially The Night of Adeaters.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
joel hodes20-Jan-11 23:46
memberjoel hodes20-Jan-11 23:46 
GeneralGreat! Pin
zeteria7-Dec-09 2:05
memberzeteria7-Dec-09 2:05 
GeneralExcelente artículo Pin
Member 37159239-Apr-08 5:29
memberMember 37159239-Apr-08 5:29 
GeneralGreat Article Pin
CodeChimp8-Nov-07 1:46
memberCodeChimp8-Nov-07 1:46 
GeneralGood Job Pin
merlin9815-Nov-07 3:54
membermerlin9815-Nov-07 3:54 
GeneralThank you Pin
Matt408831-Oct-07 11:20
memberMatt408831-Oct-07 11:20 
GeneralSorry Pin
j7tech23-Oct-07 14:35
memberj7tech23-Oct-07 14:35 
GeneralRe: Sorry Pin
yaca23-Oct-07 18:24
memberyaca23-Oct-07 18:24 
GeneralRe: Sorry Pin
J. De Mulder23-Oct-07 20:51
memberJ. De Mulder23-Oct-07 20:51 
AnswerRe: Sorry (Ditto includes source code and features Pin
sensorylogic5-Nov-07 3:24
membersensorylogic5-Nov-07 3:24 
GeneralRe: Sorry Pin
pepe3w324-Oct-07 5:30
memberpepe3w324-Oct-07 5:30 
GeneralNeat Pin
logan133723-Oct-07 8:32
memberlogan133723-Oct-07 8:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170624.1 | Last Updated 5 Nov 2007
Article Copyright 2007 by yaca
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid