Help Adding Clipboard to ListBox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AlFlo
Posts: 339
Joined: 29 Nov 2021, 21:46

Help Adding Clipboard to ListBox

Post by AlFlo » 03 Dec 2021, 15:36

I've set up a script to handle listboxes (thanks to mikeyww's help; see viewtopic.php?f=76&t=97257)

I'm wondering if I can make a listbox to show my last 10 clipboard clips as list entries. The idea would be similar to this script https://www.autohotkey.com/board/topic/94747-clipboard-content-several-items-from-the-clipboard-to-the-word/ , but without the GUI, instead saving the clips within a listbox. In other words, it would show the last 10 clips within the listbox, and then clicking any list entry would paste that clip into the current application.

My reason for wanting to put a clip function within a listbox is: (1) I'm trying to consolidate a bunch of useful functions within my multi-listbox script and (2) use less CPU/RAM in processing clips, since the listbox would only be viewed/accessed when I press a hot key.
Last edited by AlFlo on 03 Dec 2021, 15:59, edited 1 time in total.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help Adding Clipboard to ListBox

Post by mikeyww » 03 Dec 2021, 15:59

Here is a menu approach that you can adapt. viewtopic.php?p=432487#p432487

AlFlo
Posts: 339
Joined: 29 Nov 2021, 21:46

Re: Help Adding Clipboard to ListBox

Post by AlFlo » 04 Dec 2021, 13:05

Thanks, but after 4 hours of trying, I give up (I have to get back to work).

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help Adding Clipboard to ListBox

Post by mikeyww » 04 Dec 2021, 14:46

Here is an example.

Code: Select all

Global clip := [], max := 10, choices, clipNum
Gui, Font, s10
Gui, Add, ListBox, w200 r10 AltSubmit vclipNum
Gui, Add, Button, xm ym Hidden Default gWM_LBUTTONUP, OK
OnClipboardChange("clipChanged"), OnMessage(WM_LBUTTONUP := 0x0202, "WM_LBUTTONUP")

^!0::Gui, Show,, Clipboard

GuiEscape:
GuiClose:
Gui, Hide
Return

clipChanged(type) {
 If (type != 1)
  Return
 SoundBeep, 2500
 If clip.Count() = max
  clip.RemoveAt(max), choices := RegExReplace(choices, ".+\K\|.*")
 clip.InsertAt(1, Clipboard)
 GuiControl,, clipNum, % choices := "|" SubStr(Clipboard, 1, 25) "||" Trim(StrReplace(choices, "||", "|"), "|")
}

WM_LBUTTONUP(wParam := "", lParam := "") {  ; User clicked on the GUI
 Gui, Submit
 SendInput % "{Text}" clip[clipNum]
}

AlFlo
Posts: 339
Joined: 29 Nov 2021, 21:46

Re: Help Adding Clipboard to ListBox

Post by AlFlo » 05 Dec 2021, 02:48

Thank you! This is very helpful. Is there a way to make the clipboard gui stay showing after I click and insert text, instead of closing the clipboard gui and clearing all of the clips?

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help Adding Clipboard to ListBox

Post by mikeyww » 05 Dec 2021, 05:46

Sure. I'm not seeing that all of the clips are cleared. Is that what you are seeing when you run the script?

Code: Select all

Global clip := [], max := 10, choices, clipNum
Gui, Font, s10
Gui, Add, ListBox, w200 r10 AltSubmit vclipNum
Gui, Add, Button, xm ym Hidden Default gWM_LBUTTONUP, OK
OnClipboardChange("clipChanged"), OnMessage(WM_LBUTTONUP := 0x0202, "WM_LBUTTONUP")

^!0::Gui, Show,, Clipboard

GuiEscape:
GuiClose:
Gui, Hide
Return

clipChanged(type) {
 If (type != 1)
  Return
 SoundBeep, 2500
 If clip.Count() = max
  clip.RemoveAt(max), choices := RegExReplace(choices, ".+\K\|.*")
 clip.InsertAt(1, Clipboard)
 GuiControl,, clipNum
  , % choices := "|" SubStr(Clipboard, 1, 25) "||" Trim(StrReplace(choices, "||", "|"), "|")
}

WM_LBUTTONUP(wParam := "", lParam := "") {  ; User clicked on the GUI
 Gui, Submit
 Sleep, 25
 SendInput % "{Text}" clip[clipNum]
 Sleep, 50
 Gosub, ^!0
}

AlFlo
Posts: 339
Joined: 29 Nov 2021, 21:46

Re: Help Adding Clipboard to ListBox

Post by AlFlo » 05 Dec 2021, 13:08

I am seeing all of the clips cleared after I select a clip which is inserted as text. But I haven't tried integrating it yet into my other listboxes.

Perhaps when I integrate it, the clips won't disappear?

AlFlo
Posts: 339
Joined: 29 Nov 2021, 21:46

Re: Help Adding Clipboard to ListBox

Post by AlFlo » 05 Dec 2021, 13:08

I am seeing all of the clips cleared after I select a clip which is inserted as text. But I haven't tried integrating it yet into my other listboxes.

Perhaps when I integrate it, the clips won't disappear?

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Help Adding Clipboard to ListBox

Post by mikeyww » 05 Dec 2021, 13:58

I don't know. If you are referring to this exact script, there is no line that deletes all of the rows from the ListBox. I'd be interested in seeing a screenshot of before & after, when you run the script that I posted.

AlFlo
Posts: 339
Joined: 29 Nov 2021, 21:46

Re: Help Adding Clipboard to ListBox

Post by AlFlo » 09 Dec 2021, 20:14

Thanks, mikeyww. I ended up going a different route:

viewtopic.php?p=433735#p433735

Post Reply

Return to “Ask for Help (v1)”