Copy Text from edit fields to clipboard. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
reboot689
Posts: 21
Joined: 10 Apr 2017, 14:49

Copy Text from edit fields to clipboard.

20 Apr 2017, 21:26

I am trying to create a Gui that lets me enter a phone number, order number and due date variable set along with some text, and have it copy to the clipboard for me to paste elsewhere. I have searched various forums and tried the manual but reading coding manuals have never got me anywhere. heres the code i have that isnt working.

Code: Select all


^!Numpad1::
Gui, 3:Show, w200 h200, OpsDeland
Gui, 3:Add, Edit, w80 vBTN, BTN
Gui, 3:Add, Edit, w80 vSO, SO#
Gui, 3:Add, Edit, vDate, Due Date
Gui, 3:Add, Checkbox, vDispatch, Dispatch Needed?
Gui, 3:Add, Button,, Copy


buttonCOPY:
{
GuiControlGet, Checked,,Dispatch     ;Get The Value Of the checkbox 
GuiControlGet, BTN
GuiControlGet, SO
GuiControlGet, Date
if (checked == 0)
{
Clipboard= %BTN% %SO#% Due %Date% Does not need Dispatch
Return
}
Else
{
Clipboard= %BTN% %SO% Due %Date% Dispatch Needed
;Clipboard= %Subject2%
return
}}
when i try to paste it i get nothing. with other tweaks i at least got "Due Needs Dispatch"

Can someone help figure out what ive got wrong?
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Copy Text from edit fields to clipboard.

20 Apr 2017, 22:11

See GuiControlGet documentation remarks - especially:
To operate upon a window other than the default (see below), include its name or number followed by a colon in front of the sub-command (...)
For example:

Code: Select all

GuiControlGet, BTN, 3:
GuiControlGet, Checked, 3:, Dispatch
Reboot689 wrote:when i try to paste it i get nothing. with other tweaks i at least got "Due Needs Dispatch"
You also better off set a g-label instead of using the syntax buttonCopy, not sure but, for the same reason as above, this maybe could not work.

Code: Select all

Gui, 3:Add, Button, gMyLabel, Copy
return

MyLabel:
; ...
Hope this helps.
my scripts
reboot689
Posts: 21
Joined: 10 Apr 2017, 14:49

Re: Copy Text from edit fields to clipboard.

21 Apr 2017, 13:36

I did originally have a g-label in there. Ill try your suggestion and see what happens
reboot689
Posts: 21
Joined: 10 Apr 2017, 14:49

Re: Copy Text from edit fields to clipboard.

21 Apr 2017, 13:46

alright so i made the change:

Code: Select all

buttonCOPY:
{
GuiControlGet, Checked,,Dispatch     ;Get The Value Of the checkbox 
GuiControlGet, BTN, 3:
GuiControlGet, SO, 3:
GuiControlGet, Date, 3:
if (checked == 0)
{
Clipboard= %BTN% %SO#% Due %Date% Does not need Dispatch
Return

I tried versions with adding ClipWait above and below the clipboard line. no change in behavior. now upon use i get:

"BTN SO# Due Due Date Dispatch Needed"

Also, if i copy something else to the clipboard, pressing the copy button no longer copies the information from the gui back to the clipboard. How do i fix this?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Copy Text from edit fields to clipboard.

21 Apr 2017, 14:02

There are several points here, that can be improved:
1 - The repeated use of Ctrl+Alt+Num1 will cause trouble with assigning the same variable to multiple controls.
2 - The ButtonCopy syntax works for Gui #1, if you have Gui #3, you need 3ButtonCopy.
3 - Check out Gui, Submit

Code: Select all

Gui, 3: Add, Edit, w80 vBTN, BTN
Gui, 3: Add, Edit, w80 vSO, SO#
Gui, 3: Add, Edit, vDate, Due Date
Gui, 3: Add, Checkbox, vDispatch, Dispatch Needed?
Gui, 3: Add, Button,, Copy

^!Numpad1:: Gui, 3: Show, w200 h200, OpsDeland

3ButtonCopy:
    Gui, Submit
    If Dispatch
        Clipboard = %BTN% %SO% Due %Date% Dispatch Needed
    Else
        Clipboard = %BTN% %SO#% Due %Date% Does not need Dispatch
    ;MsgBox,, Clipboard, %Clipboard%, 3
Return
reboot689
Posts: 21
Joined: 10 Apr 2017, 14:49

Re: Copy Text from edit fields to clipboard.

21 Apr 2017, 15:11

This worked perfectly! thank you!

Though I am not sure what you mean by
wolf_II wrote: 1 - The repeated use of Ctrl+Alt+Num1 will cause trouble with assigning the same variable to multiple controls.
I had only used it once i DID however have to move your placement of the ^!Numpad1:: Gui, 3: Show, w200 h200, OpsDeland to above the GUI, Add block of text in order for the Gui to show more than just a blank GUI.
reboot689
Posts: 21
Joined: 10 Apr 2017, 14:49

Re: Copy Text from edit fields to clipboard.

21 Apr 2017, 15:14

But how do I keep the Gui open and have it retain my entered info, in case i end up copying something else to the clipboard before i paste what i wanted from the gui?
reboot689
Posts: 21
Joined: 10 Apr 2017, 14:49

Re: Copy Text from edit fields to clipboard.  Topic is solved

23 Feb 2018, 14:16

Alright so i figured out how to make a nice working one now. Hadn't revisited this in a while. I used Infogulch's Placeholder script for some visual Aesthetic.

Code: Select all


; Placeholder() - by infogulch for AutoHotkey v1.1.05+
; 
; to set up your edit control with a placeholder, call: 
;   Placeholder(hwnd_of_edit_control, "your placeholder text")
; 
; If called with only the hwnd, the function returns True if a 
;   placeholder is being shown, and False if not.
;   isPlc := Placeholder(hwnd_edit)
; 
; to remove the placeholder call with a blank text param
;   Placeholder(hwnd_edit, "")
; 
; http://www.autohotkey.com/forum/viewtopic.php?p=482903#482903
; 

Placeholder(wParam, lParam = "`r", msg = "") {
    static init := OnMessage(0x111, "Placeholder"), list := []
    
    if (msg != 0x111) {
        if (lParam == "`r")
            return list[wParam].shown
        list[wParam] := { placeholder: lParam, shown: false }
        if (lParam == "")
            return "", list.remove(wParam, "")
        lParam := wParam
        wParam := 0x200 << 16
    }
    if (wParam >> 16 == 0x200) && list.HasKey(lParam) && !list[lParam].shown ;EN_KILLFOCUS  :=  0x200 
    {
        GuiControlGet, text, , %lParam%
        if (text == "")
        {
            Gui, Font, Ca0a0a0
            GuiControl, Font, %lParam%
            GuiControl,     , %lParam%, % list[lParam].placeholder
            list[lParam].shown := true
        }
    }
    else if (wParam >> 16 == 0x100) && list.HasKey(lParam) && list[lParam].shown ;EN_SETFOCUS := 0x100 
    {
        Gui, Font, cBlack
        GuiControl, Font, %lParam%
        GuiControl,     , %lParam%
        list[lParam].shown := false
    }
}

^!Numpad1:: 
Gui, 3: Show, w120 h140, OpsDeland
Gui, 3: Add, Edit, w80 vBTN hwndhBtn
Gui, 3: Add, Edit, w80 vSO hwndhSO#
Gui, 3: Add, Edit, w80 vDate hwndhDueDate
Gui, 3: Add, Checkbox, vDispatch, Dispatch Needed?
Gui, 3: Add, Button,gGenerate, Generate Subject

Placeholder(hBtn, "BTN")
Placeholder(hSO#, "SO#")
Placeholder(hDueDate, "Due Date")

return

Generate: ;;Switched to G-Labels as they made everything more clear and work well. 
    Gui, Submit, NoHide
    If Dispatch
	{
        Clipboard = URGENT Order Jeopardy - %BTN% - %SO% - Due %Date% - Dispatch Needed
		;Gui, 3:Destroy ((Commenting this out prevented the information from being lost After clicking Generate))
	}	
    Else
	{
        Clipboard = URGENT Order Jeopardy - %BTN% - %SO% - Due %Date% - Does not need Dispatch
		;Gui, 3:Destroy
	}
    ;MsgBox,, Clipboard, %Clipboard%, 3
Return

3GuiClose:
Gui, 3:Destroy
Return
Sorry for not posting this update much sooner.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Billykid, dinodragon, Google [Bot], mcd and 149 guests