Pick a value from a drop down list and paste at cursor

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Stem75
Posts: 57
Joined: 18 Dec 2021, 02:37

Pick a value from a drop down list and paste at cursor

Post by Stem75 » 27 May 2022, 09:38

I have this code and as the title says, i want to pick a value and auto paste it at the cursor position in the edit area leaving the list open (and always at the top) for the next choice or until i close it.
The (shortcut - select - paste) part works but the list closes after i pick my choice.


Code: Select all

#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1
Gui,+AlwaysOnTop
Mylist := "test1|test2|test3|test4"

^RButton::    ;   left control + right click
    ;FileRead, Mylist, list.txt
    Gui Font, s10, Verbana
    Gui Add, DropDownList, gselected vitem x0 y0 w270 r45, %Mylist%
    GuiControl, Choose, item, 1
        MouseGetPos, xpos, ypos
        Gui Show, x%xpos% y%ypos%
        Gui Show, w270 h19, Quick values
Return

selected:
    Gui, submit,nohide
        sleep 150
    GuiControlGet,item
	Gui,destroy           ; when i delete this it doesn't work
	sendinput % clipboard := item
return 

GuiEscape:
GuiClose:
	gui,destroy
    ;ExitApp


Also i get this error when the list is open and i use the shortcut again.


___Screenshot   0059.png
___Screenshot 0059.png (21.32 KiB) Viewed 521 times


Thanks in advance.

Question: Can i have 2 dropdown lists and save only from 1 list the choise to cursor position;

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

Re: Pick a value from a drop down list and paste at cursor

Post by mikeyww » 27 May 2022, 09:44

You can submit the GUI, sleep for 50 ms, paste your text, and then show the GUI again. Do not destroy the GUI.

You can have any number of lists.

Code: Select all

Gui,+AlwaysOnTop
Gui, Font, s10
Gui, Add, DropDownList, w300 gSelected vitem, test1|test2|test3|test4
Gosub, F3
F3::Gui Show,, Paste (F3 = show again)

Selected:
Gui, Submit
Sleep, 50
SendInput {Text}%item%
Gosub, F3
Return

User avatar
Stem75
Posts: 57
Joined: 18 Dec 2021, 02:37

Re: Pick a value from a drop down list and paste at cursor

Post by Stem75 » 27 May 2022, 11:03

Nice and clean code as always. Thank you.

Why when i change it like this it acts crazy;

Code: Select all

F3::
Gui Show,, Paste (F3 = show again)
I modified it for 2 lists like this but i am not happy.

Code: Select all

Gui,+AlwaysOnTop
Gui, Font, s10
Gui, Add, DropDownList, w300 gSelected vitem, test1|test2|test3|test4
Gui, Add, DropDownList, w300 gSelected vitemo, test5|test6|test7|test8
Gosub, F3
F3::Gui Show,, Paste (F3 = show again)

Selected:
Gui, Submit
Sleep, 50
SendInput {Text}%item%
SendInput {Text}%itemo%
Reload
Gosub, F3
Return

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

Re: Pick a value from a drop down list and paste at cursor

Post by mikeyww » 27 May 2022, 11:16

Instead of setting a g-label, you can use a separate and new GUI button to paste both results.

Code: Select all

Gui,+AlwaysOnTop
Gui, Font, s10
Gui, Add, DropDownList, w300 vitem1 , test1|test2|test3|test4
Gui, Add, DropDownList, wp   vitem2 , test5|test6|test7|test8
Gui, Add, Button      , wp   Default, Paste
Gosub, F3
F3::Gui Show,, Paste (F3 = show again)

ButtonPaste:
Gui, Submit
Sleep, 50
SendInput {Text}%item1%%item2%
Gosub, F3
Return

User avatar
Stem75
Posts: 57
Joined: 18 Dec 2021, 02:37

Re: Pick a value from a drop down list and paste at cursor

Post by Stem75 » 27 May 2022, 13:31

Hmmm! no this is not working for me because i want to paste the value from one of the lists only and clear the values after the paste.
Your's here is doing exactly the opposite. Copies both values and doesn't clear the values after for a new start.

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

Re: Pick a value from a drop down list and paste at cursor

Post by mikeyww » 27 May 2022, 14:38

Your description is evolving, so I leave the changes to you. You can alter the paste. The concept is that you submit the GUI, and use whatever variables you like from it. GuiControl can alter controls if needed. As you post issues for other readers along the way, add details beyond "acts crazy" and "I'm not happy". Turning that into code will be difficult.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Pick a value from a drop down list and paste at cursor

Post by BoBo » 27 May 2022, 14:44

@mikeyww 1+ :eh:

User avatar
Stem75
Posts: 57
Joined: 18 Dec 2021, 02:37

Re: Pick a value from a drop down list and paste at cursor

Post by Stem75 » 27 May 2022, 16:43

"Acts crazy" means blinking very fast like a loop or something but i add a return and everything is ok.
"I'm not happy" how the script works. But the changes is up to me so...

For the rest i am starting loosing you so a big thank you for your time and for anyone reading the post or searching for this kind of thing, this is the best i came up with.
It is working fine for me and i hope the same for anyone else:

Code: Select all

Gui,+AlwaysOnTop

Mylist1 := "|test1|test2|test3"   ; You can also add    FileRead, Mylist1, List1.txt
Mylist2 := "|test4|test5|test6"   ; You can also add    FileRead, Mylist2, List2.txt
Gui Font, s10, Verbana
Gui, Add, Text, x0 y6, Value1
Gui Add, DropDownList, x60 y3 w270 r35 gselected vitem1, %Mylist1%
Gui, Add, Text, x0 y30, Value2
Gui Add, DropDownList, x60 y27 w270 r35 gselected vitem2, %Mylist2%

Gosub, ^RButton

^RButton::
        MouseGetPos, xpos, ypos
            Label:
            GuiControl, Choose, item1, 1
            GuiControl, Choose, item2, 1
            Gui Show, x%xpos% y%ypos%
            Gui Show, w330 h50, Paste values
Return

Selected:
    WinGetPos, xpos, ypos,,,Paste values
    Gui, Submit
;Sleep, 50
        SendInput %item1%
        SendInput %item2%
;Sleep, 50
    Goto, Label   ; For cleaning the selected value
Return

If anyone has the time to make it better it would be great.

Post Reply

Return to “Ask for Help (v1)”