Jump to content

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

Clipboard History - Menu - Decrementing Numbered Circular Buckets


  • Please log in to reply
8 replies to this topic
robertcollier4
  • Members
  • 141 posts
  • Last active: Jun 28 2019 01:05 AM
  • Joined: 11 Nov 2012

Here is another Clipboard History script. It will save the last 10 things (text-only) that you put into the clipboard. Then you can push the Shortcut Key (currently set to Ctrl+Alt+V) to access a menu that will popup at the location of the keyboard caret and it will show you a list based upon what you most recently put into the clipboard. You can then choose via keyboard numbered shortcut an item from the menu - and it will get sent to the location of your keyboard caret.

There are a number of things that are different about this script than others that are out there:
1. When you select a menu item - it will not put that item in the Clipboard, it will just send it via SendInput. Thus your clipboard stays intact and your Clipboard History numbering also stays intact through multiple uses of this hotkey.
2. You can use the number keys to select items from the menu for completely keyboard-only operation. You can also use the Up/Down arrow keys and Enter.
3. The list numbering operates in REVERSE - thus item #1 is the most recent thing you typed, #2 is the second most recent thing you typed. When you copy something new into the clipboard - then that becomes #1 and everything that was previously in the clipboard history gets decrmented by 1 and the last item gets dropped.
4. Menu shows at the location of the keyboard caret - not at the location of the mouse cursor. Thus it is intuitive to add something while typing.

Screenshot:
r1ahhz.jpg
 

SendMode Input  ; Forces Send and SendRaw to use SendInput buffering for speed.

^!v::
;Flush the old menu
Menu, ClipboardHistory, Add
Menu, ClipboardHistory, DeleteAll
;Create the menu items
Loop 10 {
	;Translate this loop iteration into a bucket number based upon decrementing circular bucket from CurBucket
	ThisIndexBucketNum := CurBucket - A_Index + 1
	If (ThisIndexBucketNum < 1)
		ThisIndexBucketNum := ThisIndexBucketNum + 10
	; Make 10 Display as 0 for correct keyboard shortcut
	ThisMenuItemNumber := A_Index
	If (ThisMenuItemNumber = 10)
		ThisMenuItemNumber := 0
	;Create Short Display of this Item
	StringReplace, ThisItemShortDisplay, ClipBucket%ThisIndexBucketNum%, `n, |, All ;show | for newline in menu preview
	ThisItemShortDisplay := RegExReplace(ThisItemShortDisplay, "[[:blank:]]+", " ") ;remove double spaces
	StringLeft, ThisItemShortDisplay, ThisItemShortDisplay, 64
	;Add into the menu
	Menu, ClipboardHistory, Add, % "&" . ThisMenuItemNumber . " " . ThisItemShortDisplay, PasteClipFromMenu
}
MenuShowPosY := A_CaretY + 16
Menu, ClipboardHistory, Show, %A_CaretX%, %MenuShowPosY%
Return

PasteClipFromMenu:
ThisSelectionBucketNum := CurBucket - A_ThisMenuItemPos + 1
If (ThisSelectionBucketNum < 1)
	ThisSelectionBucketNum := ThisSelectionBucketNum + 10
SendRaw % ClipBucket%ThisSelectionBucketNum%
Return

OnClipboardChange:
If (A_EventInfo = 1) {
	CurBucket++	; on first copy this will become 1
	If (CurBucket > 10)
		CurBucket := 1
	StringReplace, ClipBucket%CurBucket%, Clipboard, `r`n, `n, All ;Fix for SendInput sending Windows linebreaks 
}
Return

Edited by robertcollier4, 20 December 2012 - 07:47 PM.


zhotkey
  • Members
  • 34 posts
  • Last active: Feb 04 2016 02:06 PM
  • Joined: 02 Dec 2010
When more than one line is copied to the clipboard it pastes blank lines between them.

robertcollier4
  • Members
  • 141 posts
  • Last active: Jun 28 2019 01:05 AM
  • Joined: 11 Nov 2012

zhotkey - the problem you described has been fixed thanks to the fabulous help of the guys on this forum on this thread. The fix is included now in the first post.

ClipBucket%CurBucket% := RegExReplace(Clipboard, "\r\n?|\n\r?", "`n") ;Fix for sending Windows linebreaks in SendInput


zhotkey
  • Members
  • 34 posts
  • Last active: Feb 04 2016 02:06 PM
  • Joined: 02 Dec 2010

If you copy shortcuts to keys that are assigned by some other autohotkey script, when you paste that string from your program it executes the shortcut.  Example if you have #c defined as opening a calculator if you copy #c then paste it from your program, the string pastes, but the calculator opens.



robertcollier4
  • Members
  • 141 posts
  • Last active: Jun 28 2019 01:05 AM
  • Joined: 11 Nov 2012
If you copy shortcuts to keys that are assigned by some other autohotkey script, when you paste that string from your program it executes the shortcut.  Example if you have #c defined as opening a calculator if you copy #c then paste it from your program, the string pastes, but the calculator opens.

 

 

zhotkey - thanks for catching this, i use this script in my daily work but hadn't come across this bug yet.

http://www.autohotke...mmands/Send.htm
Raw mode: The SendRaw command sends the keystrokes exactly as they appear rather than translating {Enter} to an ENTER keystroke, ^c to Control-C, etc. To use raw mode with SendInput, SendPlay, or SendEvent, write {Raw} as the first item in the string; for example: SendInput {Raw}abc

 

The first post has been updated with this bug fixed. SendInput has been changed to SendRaw. "SendMode Input" has also been added to the top of the script to force SendRaw to use input buffering for superior speed.



faqbot
  • Members
  • 997 posts
  • Last active:
  • Joined: 10 Apr 2012
Why not:
- Add an OnExit label which saves 10 text files
- Upon startup read those 10 text files back

That way you retain your clipboard history between reloads/reboots etc...

Brandon_oma692
  • Members
  • 6 posts
  • Last active: Jun 27 2013 03:14 PM
  • Joined: 26 Dec 2012

Would it be possible to change this so the menu is always visable and in a specific position? x900 y550 for eaxmple.

 

this is similat but much better than what i was trying to create.

 

Thanks.



robertcollier4
  • Members
  • 141 posts
  • Last active: Jun 28 2019 01:05 AM
  • Joined: 11 Nov 2012
menu in a specific position? x900 y550 for eaxmple.

 

Yes. What the script currently does is place the menu at 16 pixels below (on Y axis) the current Keyboard Caret location (so it pops up underneath your current line and does not hide the current line). If you want it at a fixed position, replace:

MenuShowPosY := A_CaretY + 16
Menu, ClipboardHistory, Show, %A_CaretX%, %MenuShowPosY%

 

With:

 

MenuShowPosX := 900
MenuShowPosY := 550
Menu, ClipboardHistory, Show, %MenuShowPosX%, %MenuShowPosY%

Regarding "menu is always visible" - I don't think this is possible with "Menu" in AutoHotKey. You would need to convert this script to use "Gui" or something like that in AutoHotKey. The script is easy enough to understand that you can adapt it for GUI.



wfvdc
  • Members
  • 6 posts
  • Last active: Dec 17 2013 08:39 PM
  • Joined: 15 Nov 2012

Nice script! Very Useful! However, I have the exact oposite desire. I want the most recently copied at the bottom of the list. Where do I make the chnages in this script so that I can use it without having to reverse my workflow?

 

Again, Awesome work!