Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Preview of a Clipboard Helper (CH)


  • Please log in to reply
14 replies to this topic
shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005
The not ready for prime time, but good enough for the weekend Clipboard Helper.

Features:


* preview of captured clips
* delete captured clips
* random clip selection
* keyboard and mouse interface
Usage:

* show CH (Control+Insert or Control+v)
* show/hide CH from Tray (left-button click)
* hide CH (Escape)
* delete selected clip (context menu via right-button click)
* paste clip (Enter or left-button double-click)
* select clip (left-button click)
* browse clips (mouse or arrow up/down, home, end)
Note: Enter will paste a single clip and hide CH. However, left-button double-click will only paste a single clip.

#SingleInstance, Ignore

DetectHiddenWindows, On

; -- ignore existing clipboard content --
ignore_clipboard_change := true

; -- construct TRAY menu --
Menu, TRAY, Icon, %A_WinDir%\system32\clipbrd.exe

Menu, TRAY, NoStandard

Menu, TRAY, Add, Show Clipboard Helper, TRAY$ShowClipboardHelper
Menu, TRAY, Add
Menu, TRAY, Add, Exit Program, TRAY$ExitProgram

; -- construct main window --
Gui, +AlwaysOnTop -MinimizeBox -Resize

Gui, Add, Text, x5 y5, Target:
Gui, Add, Edit, x45 y5 w360 h20 ReadOnly vTarget

Gui, Add, ListBox, x5 y35 w400 h200 vClipboardList
Gui, Add, Edit, x5 y240 w400 h100 HScroll ReadOnly vTextPreview

Gui, Show, w410 h345 Hide, Clipboard Helper

WinGet, hw_ClipboardHelper, ID, Clipboard Helper ahk_class AutoHotkeyGUI

; -- activate message handlers --
WM_KEYUP = 0x101
OnMessage( WM_KEYUP, "HandleMessage" )

WM_LBUTTONUP = 0x202
OnMessage( WM_LBUTTONUP, "HandleMessage" )

WM_LBUTTONDBLCLK = 0x203
OnMessage( WM_LBUTTONDBLCLK, "HandleMessage" )

WM_RBUTTONUP = 0x0205
OnMessage( WM_RBUTTONUP, "HandleMessage" )

AHK_NOTIFYICON = 0x404
OnMessage( AHK_NOTIFYICON, "HandleMessage" )
return

HandleMessage( p_w, p_l, p_m, p_hw )
{
	global	WM_KEYUP, WM_LBUTTONUP, WM_LBUTTONDBLCLK, WM_RBUTTONUP, AHK_NOTIFYICON
	global	timer_PasteItem@m, timer_ShowMenu@l, timer_ShowMenu@hw
	global	hw_ClipboardHelper, ClipboardList?menu@item
	
	if ( p_m = AHK_NOTIFYICON and p_l = WM_LBUTTONUP )
	{
		SetTimer, timer_ToggleClipboardHelper, 10
	}
	else if ( A_GuiControl = "ClipboardList" )
	{
	
		if ( p_m = WM_KEYUP )
		{
			if ( p_w = 13 )
			{
				timer_PasteItem@m := p_m
				
				SetTimer, timer_PasteItem, 10
			}
			else if ( p_w = 0x26 or p_w = 0x28 or p_w = 0x23 or p_w = 0x24 )
			{
				SetTimer, timer_ShowPreview, 10
			}
			else if ( p_w = 0x2E )
			{
				SetTimer, timer_DeleteItem, 10
			}
		}
		else if ( p_m = WM_LBUTTONUP )
		{
			SetTimer, timer_ShowPreview, 10
		}
		else if ( p_m = WM_LBUTTONDBLCLK )
		{
			timer_PasteItem@m := p_m
		
			SetTimer, timer_PasteItem, 10
		}
		else if ( p_m = WM_RBUTTONUP )
		{
			timer_ShowMenu@l := p_l
		
			SetTimer, timer_ShowMenu, 10
		}
	}
	return
	
	timer_ToggleClipboardHelper:
		SetTimer, timer_ToggleClipboardHelper, off
	
		if ( DllCall( "IsWindowVisible", "uint", hw_ClipboardHelper ) )
			Gosub, HideClipboardHelper
		else
			Gosub, ShowClipboardHelper
	return
	
	timer_PasteItem:
		SetTimer, timer_PasteItem, off
		
		;LB_GETCOUNT
		SendMessage, 0x18B, 0, 0, ListBox1, ahk_id %hw_ClipboardHelper%
		
		if ( ErrorLevel = 0 )
			return
	
		GuiControlGet, item,, ClipboardList
		
		if ( timer_PasteItem@m = WM_KEYUP )
			Gosub, HideClipboardHelper
		
		PasteItem( item )
	return
	
	timer_ShowPreview:
		SetTimer, timer_ShowPreview, off
		
		GuiControlGet, item,, ClipboardList
		
		ShowPreview( item )
	return
	
	timer_ShowMenu:
		SetTimer, timer_ShowMenu, off
		
		;LB_ITEMFROMPOINT
		SendMessage, 0x1A9, 0, timer_ShowMenu@l, ListBox1, ahk_id %hw_ClipboardHelper%
		
		if ( ErrorLevel = 0x1FFFF or ( ErrorLevel & 0x10000 ) )
			return
			
		ClipboardList?menu@item := ErrorLevel+1
		
		GuiControl, Choose, ClipboardList, %ClipboardList?menu@item%
		Gosub, timer_ShowPreview

		if ClipboardList?menu=
		{
			Menu, ClipboardList?menu, Add, Delete, ClipboardList?menu$delete
		}
		
		Menu, ClipboardList?menu, Show
	return
	
	timer_DeleteItem:
		SetTimer, timer_DeleteItem, off
		
		;LB_GETCURSEL
		SendMessage, 0x188, 0, 0, ListBox1, ahk_id %hw_ClipboardHelper%
		
		DeleteItem( ErrorLevel )
	return
}

TRAY$ExitProgram:
ExitApp

TRAY$ShowClipboardHelper:
	Gosub, ShowClipboardHelper
return

ClipboardList?menu$delete:
	DeleteItem( ClipboardList?menu@item-1 )
return

GuiEscape:
HideClipboardHelper:
	SetTimer, timer_MonitorTarget, off

	Gui, Hide
return

~LButton::
	SetTimer, timer_MonitorTarget, off
return

~LButton up::
	SetTimer, timer_MonitorTarget, on
return	

^v::
+Insert::
ShowClipboardHelper:
	WinGet, hw_active, ID, A
	ControlGetFocus, control_active, A
	UpdateTarget( hw_active, control_active )

	Gui, Show
	
	ControlFocus, ListBox1, ahk_id %hw_ClipboardHelper%
	
	SetTimer, timer_MonitorTarget, 200
return

timer_MonitorTarget:
	WinGet, hw_active, ID, A
	ControlGetFocus, control_active, A

	UpdateTarget( hw_active, control_active )
return

OnClipboardChange:
	if ( ignore_clipboard_change )
		ignore_clipboard_change := false
	else if ( A_EventInfo = 1 )
		AddItem( Clipboard )
return

AddItem( p_item )
{
	global	hw_ClipboardHelper
	
	fill := Chr( 1 )
	StringReplace, p_item, p_item, |, %fill%, All

	;LB_GETCOUNT
	SendMessage, 0x18B, 0, 0, ListBox1, ahk_id %hw_ClipboardHelper%
	items := ErrorLevel

	loop, %items%
	{
		;LB_GETTEXTLEN
		SendMessage, 0x18A, A_Index-1, 0, ListBox1, ahk_id %hw_ClipboardHelper%
		len := ErrorLevel
		
		VarSetCapacity( text, len, 1 )
		
		;LB_GETTEXT
		SendMessage, 0x189, A_Index-1, &text, ListBox1, ahk_id %hw_ClipboardHelper%
		
		if ( p_item = text )
		{
			GuiControl, Choose, ClipboardList, %A_Index%
			
			ShowPreview( p_item )
		
			p_item=
			
			break
		}
	}
	
	if p_item!=
	{
		GuiControl,, ClipboardList, %p_item%
		
		items++
		GuiControl, Choose, ClipboardList, %items%

		ShowPreview( p_item )
		
		MsgBox, 4160, Clipboard Helper, Capture complete!, 0.4
	}
}

DeleteItem( p_item )
{
	global	hw_ClipboardHelper
	
	;LB_DELETESTRING
	SendMessage, 0x182, p_item, 0, ListBox1, ahk_id %hw_ClipboardHelper%

	p_item++	
	if ( p_item > 1 )
		p_item--
	
	GuiControl, Choose, ClipboardList, %p_item%
	
	GuiControlGet, item,, ClipboardList
	ShowPreview( item )
}

PasteItem( p_item )
{
	global	target?hw, target?control, ignore_clipboard_change
	
	fill := Chr( 1 )
	StringReplace, p_item, p_item, %fill%, |, All

	ignore_clipboard_change := true
	
	Clipboard := p_item
	
	ControlFocus, %target?control%, ahk_id %target?hw%
	
	Send, +{Insert}
}

ShowPreview( p_item )
{
	fill := Chr( 1 )
	StringReplace, p_item, p_item, %fill%, |, All

	GuiControl,, TextPreview, %p_item%
}

UpdateTarget( p_hw, p_control )
{
	global	hw_ClipboardHelper, target?hw, target?control

	if ( p_hw = hw_ClipboardHelper )
		return
		
	target?hw := p_hw
	target?control := p_control

	WinGetTitle, title, ahk_id %target?hw%

	GuiControl,, Target, %title%
}


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Wow, even without the future enhancements, that's really slick multi-clipboard script. It also has the most advanced use of OnMessage I've ever seen. Most importantly, it's very easy to use due to a well-designed, intuitive user interface.

Thanks for sharing it.

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

it's very easy to use due to a well-designed, intuitive user interface.


Thanks. If you like where this is going, you really should check out ClipMate. It inspired this design. Although, I still have a long way to go before I can match, let alone replace it.

Thanks for sharing it.


Sure. I have noticed, on and off, that others find value in my contributions. If not whole, then at least in pieces.

Oh well. I also look for items of specific interest to myself.

Edit:

I just tried their new version 7. The program has really evolved since its introduction. A lot of thoughtful, well implemented features, which I am sure the AHk community would love to play with.

Nemroth
  • Members
  • 278 posts
  • Last active: Dec 31 2011 10:53 PM
  • Joined: 07 Sep 2004
At first, thanks a lot for this very good script. You said you wanted to add more keyboard shortcuts. I propose this one, witch seems to lack :

Usage:

* delete selected clip (context menu via right-button click)

The more simple wouldn't be to use the Del key to delete the selected clip ?
Thanks again for the good job.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I use a keyboard manager, which inserts Unicode characters into MS Word via the clipboard, and also a math expression evaluator, which copies and pastes equations to Pari/GP. These are slowed down or prevented to work by the Clipboard Helper. Therefore, I'd like a more selective version, where other hotkeys copy clipboards to the buffer, not Ctrl-C, which should remain undisturbed. (Many of us accustomed to have Ctrl-C/V act as single keystrokes, and a popup window, or an extra Enter key is confusing and slowing us down.)

I use a version of my old Deluxe Clipboard script, where CapsLock & C copies the selection to a named private clipboard, CapsLock & A appends the selection, CapsLock & V pastes the named clipboard, etc. It does not interfere with any normal use of the Windows clipboard. (It lacks the preview, though, which I'd like to steal from your script, but I need the named clipboard and the append functionality.)

Somehow Clipboard Helper once interfered with MultiEdit 9.10, my favorite editor. After copying a line to the clipboard, at an attempt to paste it back the window title started to flicker and no input was possible until I shut down the script.

The target box does not seem to be important: of course we want to paste to the window, where Ctrl-C was pressed.

It is a very nice script. Have you seen the versions of Decarlo110 and Skromel?

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

The more simple wouldn't be to use the Del key to delete the selected clip ?


You're right.

It was left out as I was trying to decide what balance to strike between a mouse and keyboard interface. Since I decided on left-button double-click to paste, this addition will be straightforward.

Check the first post for the updated version.

Thanks again for the good job.


I am glad it works for you.

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

a more selective version, where other hotkeys copy clipboards to the buffer, not Ctrl-C, which should remain undisturbed.
...
a popup window, or an extra Enter key is confusing and slowing us down.
...
CapsLock & C copies the selection to a named private clipboard, CapsLock & A appends the selection, CapsLock & V pastes the named clipboard, etc.


The present implementation captures all text on the clipboard using OnClipboardChange to trigger the capture. I can't think of any reason not to change the current mechanism. I'll consider how to introduce the change in the most transparent manner possible.

All these changes can be implemented in a straightforward manner with the introduction of a configuration interface -- that should probably be the priority.

It lacks the preview, though, which I'd like to steal from your script, but I need the named clipboard and the append functionality.


This preview release was meant as a concept demonstration. If there are specific pieces which interest you, go ahead and cannibalize it.

Somehow Clipboard Helper once interfered with MultiEdit 9.10, my favorite editor.


When I have the opportunity, I will install MultiEdit and test this.

The target box does not seem to be important: of course we want to paste to the window, where Ctrl-C was pressed.


The target box indicates where a clip will be pasted and is essential for the mouse interface to work properly. When pasting a clip via left-button double-click, this feature informs the user which target window will be the recipient of the pasted clip.


Have you seen the versions of Decarlo110 and Skromel?


I just checked them. They each have features and behaviors of merit.

As with my other contributions, the primary purpose is an exchange of knowledge. If others find the contribution useful, then all the better.

The public posts are a way for others to share in my quest for greater knowledge and understanding.

Atomhrt
  • Members
  • 124 posts
  • Last active: Nov 13 2006 09:18 PM
  • Joined: 02 Sep 2004

Thanks. If you like where this is going, you really should check out ClipMate. It inspired this design. Although, I still have a long way to go before I can match, let alone replace it.


While I think that ClipMate is really nice and I am a registered user, I wanted something a bit less bloated and, for me, easier to use. I've been using Ditto-cp for a long time now.
http://ditto-cp.sourceforge.net/
I am he of whom he speaks!

TGKS
  • Guests
  • Last active:
  • Joined: --
Beep Beep Beep Beep Beep Beep Beep

I hope you get the idea!! I like the Clipboard Helper but that darn infernal Beep just drives me nuts. When I'm copying multiple items I don't want to hear a beep every time. The splash screen I can live with but how can you turn off that beep.

In case you can't see :shock: I'm a newbie too AutoHotkey.

Why not
  • Guests
  • Last active:
  • Joined: --
Very good indeed!!!
One little thing: I try to shift the gui at the right but the gui stay at the center, Why, please?
Gui, Show, x500 y0 w740 h990 Hide, Clipboard Helper
Why not an Gui hide after a "enter" and "double click left" (only a idea)
Thank you for sharing!!!

  • Guests
  • Last active:
  • Joined: --
Try ArsClip

LazFishEnt_As_Guest
  • Guests
  • Last active:
  • Joined: --
How can I make it save all the clips between sessions? I tried for like an hour. plz help.

MarkyMark
  • Members
  • 32 posts
  • Last active: Jul 02 2013 03:12 PM
  • Joined: 28 Sep 2007
Useful script. it'd be nice to be able to save clips through sessions.

:)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Use CLCL - the state of the art open-source clipboard manager.
Posted Image

Larry
  • Members
  • 63 posts
  • Last active: Jan 05 2019 04:39 AM
  • Joined: 03 Mar 2005
Nice little utility, but I'm experiencing one small problem.

I tried copying some snippets of Regex Code to the clipboard, but
everywhere there is a vertical bar in the code, a little square is
displayed in it's place. This causes a definite readability problem.

Is there a work-around of any kind for this problem. Thanks.