Copy highlighted text and paste into another application and hit enter

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
matt_in_portugal
Posts: 10
Joined: 12 Nov 2021, 15:05

Copy highlighted text and paste into another application and hit enter

Post by matt_in_portugal » 27 Sep 2022, 04:48

Hello.

I need to create a script that copies the highlighted text (from any windows application that i am in) and then pastes it into another specific application (a VOIP softphone called Zoiper) and then actions the enter button. I have been using a similar script on an old machine as per below, but it is not working. Can anyone help, please?

Thanks,
Matt

Code: Select all

#esc::
clipboard =
Send ^c
ClipWait
IniWrite % Clipboard, Save.ini, Data, Myclip

Run "C:\Program Files (x86)\Zoiper\Zoiper.exe"
WinActivate, Zoiper Biz

IniRead Myclip, Save.ini, Data, Myclip
Send % Myclip

Send {Enter}
Return
Last edited by BoBo on 27 Sep 2022, 04:54, edited 1 time in total.
Reason: Added [code][/code]-tags.

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

Re: Copy highlighted text and paste into another application and hit enter

Post by BoBo » 27 Sep 2022, 04:58

probable window detection or a timing issue
SetTitleMatchMode/WinWaitActive

matt_in_portugal
Posts: 10
Joined: 12 Nov 2021, 15:05

Re: Copy highlighted text and paste into another application and hit enter

Post by matt_in_portugal » 27 Sep 2022, 07:07

HI bobo. Please can you give example of what i should add to the script? thanks

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

Re: Copy highlighted text and paste into another application and hit enter

Post by BoBo » 27 Sep 2022, 07:13

Code: Select all

SetTitleMatchMode, 2

#esc::
clipboard := ""
Send ^c
ClipWait
myClip := clipboard
IniWrite, % myClip, Save.ini, Data, myClip

Run "C:\Program Files (x86)\Zoiper\Zoiper.exe"
WinWaitActive, Zoiper Biz

;IniRead, myClip, Save.ini, Data, myClip
Send % myClip
Sleep 100
Send {Enter}
Return

matt_in_portugal
Posts: 10
Joined: 12 Nov 2021, 15:05

Re: Copy highlighted text and paste into another application and hit enter

Post by matt_in_portugal » 27 Sep 2022, 07:24

Thank you for such a quick reply @BoBo

I updated with your script and first instance of using the script works as intended. But..

2nd time trying - cuts the original number and leaves the letter c in place of the highlighted numbers (I am highlighting a phone number in an ms word document and then using shift+esc (+esc::) to run the script
3rd time trying does nothing at all

Strange? Any ideas are appreciated :)

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

Re: Copy highlighted text and paste into another application and hit enter

Post by BoBo » 27 Sep 2022, 08:32

Guessing,
...the remaining letter c at your second attempt is because Send ^c has ignored/wasn't able to process the CTRL-key.

So, you could try using a workaround by replacing

Code: Select all

;Send ^c 
Send {Ctrl Down}c{Ctrl Up}

and even slow down the process by using whatever Sleep between keystrokes.
...not working at all could be the outcome of using ClipWait without a parameter. See AHK's Help file for details.

Good luck.

Edit: fixed code as mentioned by @gregster below. Thx

matt_in_portugal
Posts: 10
Joined: 12 Nov 2021, 15:05

Re: Copy highlighted text and paste into another application and hit enter

Post by matt_in_portugal » 27 Sep 2022, 12:54

@BoBo
swapping out Send ^c for Send {Ctrl Down} c {Ctrl Up} fixed it.
Many thanks for your kind help.
Greetings from Portugal

gregster
Posts: 8922
Joined: 30 Sep 2013, 06:48

Re: Copy highlighted text and paste into another application and hit enter

Post by gregster » 27 Sep 2022, 12:59

jftr, with Send {Ctrl Down} c {Ctrl Up} , you are also sending (control)-spaces before and after c; hence, I would generally suggest (although the spaces might do no harm in this situation):

Code: Select all

Send {Ctrl Down}c{Ctrl Up}	; without spaces

Post Reply

Return to “Ask for Help (v1)”