A program to paste frequently used text Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AndrewKun
Posts: 24
Joined: 03 Jun 2015, 12:03

A program to paste frequently used text

14 Sep 2016, 12:20

Hi guys, I would really appreciate your help in creating a simple script/program that would do the following:

1. Show a ListBox with predefined items, like: Item1, Item2, Item3 e.t.c
2. When I click on any item, it would copy a predefined text for this item in the clipboard. The text can contain line breaks.
3. Close ListBox

For example when I click Item1, the text is copied to clipboard "You have clicked Item1", and then closes the ListBox window. In reality the text can be quite big, with line breaks, empty lines e.t.c.

All I can do for now is:

Code: Select all

#k::
GUI, New
GUI, Add, ListBox
GUI, Show
return
How can I fill it with items and create an action to copy text? Can't understand the manuals very well.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: A program to paste frequently used text

14 Sep 2016, 12:38

Here's a basic example/template.
Hope this helps :)

Code: Select all

TextItem1 =  ; see "Splitting a Long Line into a Series of Shorter Ones" for more info: https://autohotkey.com/docs/Scripts.htm#continuation
    (LTrim Join`r`n
        Lorem ipsum dolor sit 
        amet, consectetur 
        adipiscing elit, 
    )

TextItem2 = 
    (LTrim Join`r`n
        sed do eiusmod tempor 
        incididunt ut labore 
        et dolore magna aliqua.
    )
return  ; End of Auto-execute section: https://autohotkey.com/docs/Scripts.htm#auto

#k::
    Gui, Add, ListBox, vChoice gItemSelected, Item1|Item2
    Gui, Show
return

ItemSelected:
    Gui, Submit
    Gui, Destroy
    Clipboard := Text%Choice%  ; Copies TextItem1/TextItem2/etc. to the clipboard
    TrayTip, Item Copied, %Choice% has been copied to the clipboard.
return

GuiClose:
    Gui, Destroy
return

^Esc::ExitApp  ; Ctrl+Escape closes this script
Let me know if there is anything that doesn't make sense.
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: A program to paste frequently used text  Topic is solved

14 Sep 2016, 15:28

What about something like this:

Code: Select all

Gui, Add, Tab2, vMyTabs w400 h400, Subject|Salutation|Text
Gui, Tab, Subject
Gui, Add, Button, gMyText, Letter of application for a position`n`n
Gui, Add, Button, gMyText, application for a traineeship`n`n
Gui, Tab, Salutation
Gui, Add, Button, gMyText, Ladies and gentlemen,,`n`n
Gui, Add, Button, gMyText, Dear Mrs,`n`n
Gui, Tab, Text
Gui, Add, Button, gMyText, 1st Text - 1st Line`n1st Text - 2nd Line
Gui, Add, Button, gMyText, 2nd Text - 1st Line`n2nd Text - 2nd Line`n2nd Text - 3rd Line
Gui, Show,w400 h400, Letter
return

MyText:
MouseGetPos,,,, Control
ControlGetText, Text, %Control%
Gui, Submit
Sleep, 50
clipboard = %Text%
; SendInput, %Text%
Gui, Show
return

GuiClose:
Exitapp
AndrewKun
Posts: 24
Joined: 03 Jun 2015, 12:03

Re: A program to paste frequently used text

14 Sep 2016, 16:29

kon, GEV, thank you both very much for the help. I've looked through the manuals and at least now understand what the code does :)

Actually, I've combined the methods from both solutions to create a tabbed listboxes :) Something like below, looking really good so far, but now I feel I have some excess code which could be trimmed somehow:

Code: Select all

TextItem1 =  ; see "Splitting a Long Line into a Series of Shorter Ones" for more info: https://autohotkey.com/docs/Scripts.htm#continuation
	(LTrim Join`r`n
		Lorem ipsum dolor sit 
		amet, consectetur
		adipiscing elit, 
	)

TextItem2 = 
	(LTrim Join`r`n
		sed do eiusmod tempor 
		incididunt ut labore 
		et dolore magna aliqua.
	)
	
TextItem3 = 
	(LTrim Join`r`n
		Some more text here
		Blah blah blah
	)
	
TextItem4 = 
	(LTrim Join`r`n
		Once again
		Some more text
	)
return

#k::
	Gui, Add, Tab2, vMyTabs H250 W200, Subject|Salutation|Text
	Gui, Tab, Subject
	Gui, Add, ListBox, vChoice1 gItemSelected1 W150 H200, Item1|Item2|Item3|Item4
	Gui, Tab, Salutation
	Gui, Add, ListBox, vChoice2 gItemSelected2 W150 H200, Item5|Item6|Item7|Item8
	Gui, Tab, Text
	Gui, Add, ListBox, vChoice3 gItemSelected3 W150 H200, Item9|Item10|Item11|Item12
	Gui, Show
return

ItemSelected1:
	Gui, Submit
	Gui, Destroy
	Clipboard := Text%Choice1%  ; Copies TextItem1/TextItem2/etc. to the clipboard
	TrayTip, Item Copied, %Choice% has been copied to the clipboard.
return

ItemSelected2:
	Gui, Submit
	Gui, Destroy
	Clipboard := Text%Choice2%  ; Copies TextItem1/TextItem2/etc. to the clipboard
	TrayTip, Item Copied, %Choice% has been copied to the clipboard.
return

ItemSelected3:
	Gui, Submit
	Gui, Destroy
	Clipboard := Text%Choice3%  ; Copies TextItem1/TextItem2/etc. to the clipboard
	TrayTip, Item Copied, %Choice% has been copied to the clipboard.
return

GuiClose:
	Gui, Destroy
return

^Esc::ExitApp  ; Ctrl+Escape closes this script
I don't know how to get rid of the many versions of "ItemSelected" function and "Choice" variables, but at least it works! :bravo:
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: A program to paste frequently used text

15 Sep 2016, 14:45

AndrewKun wrote:I don't know how to get rid of the many versions of "ItemSelected" function and "Choice" variables
Maybe...

Code: Select all

; Add the other items (only 1/5/10 currently defined)
TextItem1 =  ; see "Splitting a Long Line into a Series of Shorter Ones" for more info: https://autohotkey.com/docs/Scripts.htm#continuation
	(LTrim Join`r`n
		Lorem ipsum dolor sit 
		amet, consectetur
		adipiscing elit, 
	)

TextItem5 = 
	(LTrim Join`r`n
		sed do eiusmod tempor 
		incididunt ut labore 
		et dolore magna aliqua.
	)
	
TextItem10 = 
	(LTrim Join`r`n
		Some more text here
		Blah blah blah
	)
return

#k::
	Gui, Add, Tab2, vMyTabs H250 W200, Subject|Salutation|Text
	Gui, Tab, Subject
	Gui, Add, ListBox, vChoice1 gItemSelected W150 H200, Item1|Item2|Item3|Item4
	Gui, Tab, Salutation
	Gui, Add, ListBox, vChoice2 gItemSelected W150 H200, Item5|Item6|Item7|Item8
	Gui, Tab, Text
	Gui, Add, ListBox, vChoice3 gItemSelected W150 H200, Item9|Item10|Item11|Item12
	Gui, Show
return

ItemSelected:
	Gui, Submit
    Choice := %A_GuiControl%
	Clipboard := Text%Choice%  ; Copies TextItem1/TextItem2/etc. to the clipboard
	TrayTip, Item Copied, %Choice% has been copied to the clipboard.
    Gui, Destroy
return

GuiClose:
	Gui, Destroy
return

^Esc::ExitApp  ; Ctrl+Escape closes this script

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], MrHue, Rohwedder, Rxbie, songdg and 337 guests