How to display a list and copy to clipboard a selected text (see example)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

How to display a list and copy to clipboard a selected text (see example)

17 Oct 2018, 17:36

So this what i look for:

I have personal information in my computer, like my social number, login name at several sites etc. etc.

Now, when i need it, i open up a txt file with all of these information in it, then, i have to select a line, copy it, then paste it to (for example) an login page

I would prefer if it could be this way:

press a key combination like ctrl+i and this would be triggered to open an list with all of my personal info and with the option to select all (line) and then copy it to clipboard, or even more handy, select a line and it will then automatic copy this line of text to the clipboard which then can be pasted in any window

I know i ask alot, but it would be very helpfull if this can be done with ahk
eqv
Posts: 72
Joined: 18 Sep 2018, 22:17

Re: How to display a list and copy to clipboard a selected text (see example)

17 Oct 2018, 19:56

loek3000 wrote:
17 Oct 2018, 17:36
So this what i look for:

I have personal information in my computer, like my social number, login name at several sites etc. etc.

Now, when i need it, i open up a txt file with all of these information in it, then, i have to select a line, copy it, then paste it to (for example) an login page

I would prefer if it could be this way:

press a key combination like ctrl+i and this would be triggered to open an list with all of my personal info and with the option to select all (line) and then copy it to clipboard, or even more handy, select a line and it will then automatic copy this line of text to the clipboard which then can be pasted in any window

I know i ask alot, but it would be very helpfull if this can be done with ahk
Try this script:
(replace «"C:\Users\·\Desktop\test.txt"» at the start with your file path)

Code: Select all

^i::
If !(gFile) {
	gFile:="C:\Users\·\Desktop\test.txt"
	GoSub, ClipGui
} else {
	Gui, clip: destroy
	If (gChoose<>"") {
	gFile := StrSplit(gFile,"|")
	While !(strSplit(gChoose,"|")[a_index]="")
	gClip .= (a_index=1?"":"`r`n") . gFile[strSplit(gChoose,"|")[a_index]]
	Clipboard := gClip, gClip:=""
	SplashTextOn, 50, 23,, Copy!
	Sleep, 700
	SplashTextOff
	} gFile:=gChoose:=""
} Return

ClipGui:
	FileRead, gFile, % gFile
	gFile:=StrReplace(gFile,"`r`n","|") . "|", gg:=1
	Gui,clip: Font, s14 cRed, Lucida Console
	Gui,clip: Add, ListBox,w200 multi vVar gChoser altsubmit h140  ,%gFile%
	GuiControl,clip: Choose, Var,12
	Gui,clip:show
	Return
Choser:
	Gui,clip:Submit,Nohide
	GuiControlGet, gChoose,,Var
	Return
• Ctrl+i: Activate Script [show list].
• Select line(s) to copy to clipboard.
• {again} Ctrl+i: Copy selection to clipboard ("Copy!" notification).
+ If no press anything (no selection), clipboard don't change

Hope it helps,
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 03:06

Ah great thank you !

But i thing? instead of selecting a line (which is good) can it be copied into clipboard by double click it instead of (again) ctrl-i ?

so in this script, it will open the file, i select a line of text to be copied by double clicking on it

just a second, i will upload a picture
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 03:24

Thanx, but, a password manager would not do the trick for me, i want to be able to quicly display and copy a textline...

But i added a screenshot:

Image
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 03:40

loek3000 wrote:
18 Oct 2018, 03:24
a password manager would not do the trick for me
i beg to differ
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 03:46

Ok, well, i asked for help on ahk, because i don't want to install another app... thanx anyway
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 03:49

I want to give it a try tho...... what's the name of this PW manager?
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 04:09

Thanx, i've installed it (because i already did a search) and i'm searching for the display you have in your example here, where you have to (only) double click, but i don't see it
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 04:35

listview double click example:

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1

myTxtFile = 
(
row1key|row1value
row2key|row2value
)

Gui Add, ListView, r10 Grid gLvHandler +HWNDhLV, Key|Value
for each, Line in StrSplit(myTxtFile, "`n", "`r")
{
	Columns := StrSplit(Line, "|")
	LV_Add("", Columns*)
}
LV_ModifyCol()
Gui Show
Return

GuiClose:
GuiEscape:
	ExitApp
Return

LvHandler:
	if (A_GuiEvent == "DoubleClick")
	{
		Row := A_EventInfo
		Col := LV_SubitemHitTest(hLV)

		LV_GetText(result, Row, Col)
		Clipboard := result

		MsgBox % "copied: " Clipboard
	}
Return

; https://autohotkey.com/board/topic/80265-solved-which-column-is-clicked-in-listview/
LV_SubitemHitTest(HLV) {
   ; To run this with AHK_Basic change all DllCall types "Ptr" to "UInt", please.
   ; HLV - ListView's HWND
   Static LVM_SUBITEMHITTEST := 0x1039
   VarSetCapacity(POINT, 8, 0)
   ; Get the current cursor position in screen coordinates
   DllCall("User32.dll\GetCursorPos", "Ptr", &POINT)
   ; Convert them to client coordinates related to the ListView
   DllCall("User32.dll\ScreenToClient", "Ptr", HLV, "Ptr", &POINT)
   ; Create a LVHITTESTINFO structure (see below)
   VarSetCapacity(LVHITTESTINFO, 24, 0)
   ; Store the relative mouse coordinates
   NumPut(NumGet(POINT, 0, "Int"), LVHITTESTINFO, 0, "Int")
   NumPut(NumGet(POINT, 4, "Int"), LVHITTESTINFO, 4, "Int")
   ; Send a LVM_SUBITEMHITTEST to the ListView
   SendMessage, LVM_SUBITEMHITTEST, 0, &LVHITTESTINFO, , ahk_id %HLV%
   ; If no item was found on this position, the return value is -1
   If (ErrorLevel = -1)
      Return 0
   ; Get the corresponding subitem (column)
   Subitem := NumGet(LVHITTESTINFO, 16, "Int") + 1
   Return Subitem
}
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 06:11

Ah nice !! :)

almost perfect for me, but instead of putting all of the data into this script, can it read a .txt file instead?

if not i'm very happy with this already

thank you so much :)
loek3000
Posts: 146
Joined: 12 Nov 2013, 03:24

Re: How to display a list and copy to clipboard a selected text (see example)

18 Oct 2018, 07:13

Nevermind, this is just as perfect for me as i was looking for
i added several rows and made the window a little wider..

thanks alot, this was just what i was looking for :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, mikeyww, RussF and 179 guests