Please help me auto paste into Notepad++. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Please help me auto paste into Notepad++.

05 Jan 2022, 02:04

I think the code below is what I need, I just don't know how to dress it up:

Code: Select all

ControlSend, Scintilla1, ^v, ahk_exe Notepad++.exe
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: Please help me auto paste into Notepad++.

05 Jan 2022, 04:08

Sorry my English is horrible and I don't know what "dress it up" means

This sends Ctrl + V only to Notepad ++. Exe by function key <F1>

Code: Select all

#If WinActive("ahk_exe Notepad++.exe")
F1::
ControlSend, Scintilla1, ^v, ahk_exe Notepad++.exe
#If
Donec Perficiam
Rohwedder
Posts: 7733
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Please help me auto paste into Notepad++.

05 Jan 2022, 04:17

Hallo,
auto paste with each change of the clipboard:

Code: Select all

#Persistent
OnClipboardChange("AutoPaste")
Return
AutoPaste()
{
    ControlSend, Scintilla1, ^v, ahk_exe Notepad++.exe
}
User avatar
boiler
Posts: 17279
Joined: 21 Dec 2014, 02:44

Re: Please help me auto paste into Notepad++.

05 Jan 2022, 07:16

jmeneses wrote: This sends Ctrl + V only to Notepad ++. Exe by function key <F1>

Code: Select all

#If WinActive("ahk_exe Notepad++.exe")
F1::
ControlSend, Scintilla1, ^v, ahk_exe Notepad++.exe
#If
In case the above version is used, I just wanted to note that it can lead to bad results depending on what may follow it in the script. Always use return at the end of a hotkey subroutine:

Code: Select all

#If WinActive("ahk_exe Notepad++.exe")
F1::
ControlSend, Scintilla1, ^v, ahk_exe Notepad++.exe
return
#If
...or make it a single-line hotkey which has an implied return:

Code: Select all

#If WinActive("ahk_exe Notepad++.exe")
F1::ControlSend, Scintilla1, ^v, ahk_exe Notepad++.exe
#If

Example of why this is necessary:

Code: Select all

#IfWinActive, ahk_exe Notepad++.exe
F1::
MsgBox, Only this message is meant to be displayed when F1 is pressed.
#If

F2::
MsgBox, This is the subroutine where all the data files are deleted.
return
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: Please help me auto paste into Notepad++.

07 Jan 2022, 01:55

In case the above version is used, I just wanted to note that it can lead to bad results depending on what may follow it in the script. Always use return at the end of a hotkey subroutine:
You're right Boiler, thanks for keeping an eye on me🤦‍♀️🤦‍♀️

I always forget the RETURN, it is a mistake of mine that luckily I quickly detect
Donec Perficiam
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Please help me auto paste into Notepad++.

23 Feb 2022, 12:26

Code: Select all

#SingleInstance, Force
#Persistent
OnClipboardChange("ClipChanged")
return
ClipChanged() {
	ControlSend, Scintilla1, ^v`n, ahk_exe Notepad++.exe
}
return
Esc::MsgBox BYE
ExitApp
This script won't exit, why? I only added a MsgBox.
gregster
Posts: 9096
Joined: 30 Sep 2013, 06:48

Re: Please help me auto paste into Notepad++.

23 Feb 2022, 12:31

Esc::MsgBox BYE is a one-liner hotkey (which makes the following ExitApp unreachable).
To create a multi-line hotkey, you have to leave the right side of :: empty:

Code: Select all

Esc::
MsgBox BYE
ExitApp
Compare the hotkey introduction: https://www.autohotkey.com/docs/Hotkeys.htm#Intro
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Please help me auto paste into Notepad++.

10 Mar 2022, 16:34

Corrected:

Code: Select all

#SingleInstance, Force
#Persistent
OnClipboardChange("ClipChanged")
return
ClipChanged() {
	ControlSend, Scintilla1, ^v`n, ahk_exe Notepad++.exe
}
return
Esc::
MsgBox BYE
ExitApp

This script works when Notepad++ doesn't exist, now I want to make this script work even if the app does exist. I don't know how to do this.
User avatar
boiler
Posts: 17279
Joined: 21 Dec 2014, 02:44

Re: Please help me auto paste into Notepad++.

10 Mar 2022, 20:46

LAPIII wrote: This script works when Notepad++ doesn't exist, now I want to make this script work even if the app does exist.
How could it work if Notepad++ doesn’t exist when its purpose is to send to the Notepad++ window?
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Please help me auto paste into Notepad++.

10 Mar 2022, 22:10

I'm sorry that I got that reversed.
User avatar
boiler
Posts: 17279
Joined: 21 Dec 2014, 02:44

Re: Please help me auto paste into Notepad++.

10 Mar 2022, 22:40

OK, so if we reverse it, how would you want this script, whose action is to send text to the Notepad++ window, to work when the Notepad++ window doesn’t exist? Where would it send it?
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Please help me auto paste into Notepad++.

10 Mar 2022, 22:56

The script should open notepad++. This is a what I got, but I got stuck on line 10:

Code: Select all

#SingleInstance, Force
#Persistent
OnClipboardChange("ClipChanged")
return
If !Winexist("ahk_exe notepad++.exe")
{	
Run, C:\Program Files (x86)\Notepad++\notepad++.exe	
}
else
ClipChanged() {
	ControlSend, Scintilla1, ^v`n, ahk_exe Notepad++.exe
}
return
User avatar
boiler
Posts: 17279
Joined: 21 Dec 2014, 02:44

Re: Please help me auto paste into Notepad++.

10 Mar 2022, 23:06

There's more wrong with it before that. First of all, nothing from line 5 to line 9 would ever get executed because it's not in the auto-execute section and not inside something that gets called. It's just sitting there in limbo, unreachable, never in the script's code flow.

Second, you don't put a function definition inline with regular code in order to execute it like you did after the "else" statement. You put function calls inline with other code. If it made sense to do what you were attempting to do, that section of code would look like this:

Code: Select all

If !Winexist("ahk_exe notepad++.exe")
	Run, C:\Program Files (x86)\Notepad++\notepad++.exe	
else
	ClipChanged() ; this a function call
return

; this is the function:
ClipChanged() {
	ControlSend, Scintilla1, ^v`n, ahk_exe Notepad++.exe
}
So when the clipboard changes and Notepad++ isn't open, you want it to open Notepad++ (and do nothing else)? And if it is open, then you want the clipboard sent to it? Then I suppose you are trying to do something like this:

Code: Select all

#SingleInstance, Force
#Persistent
OnClipboardChange("ClipChanged")
return

ClipChanged() {
	if !Winexist("ahk_exe notepad++.exe")
		Run, C:\Program Files (x86)\Notepad++\notepad++.exe	
	else
		ControlSend, Scintilla1, ^v`n, ahk_exe Notepad++.exe
}
User avatar
boiler
Posts: 17279
Joined: 21 Dec 2014, 02:44

Re: Please help me auto paste into Notepad++.  Topic is solved

10 Mar 2022, 23:37

Edit: This post was written in response to a post by LAPIII that he has since deleted.

It doesn’t just open on its own. You have to copy something to the clipboard first. Like I said, it’s not at all clear what you are trying to achieve. If all you want to do is have it open Notepad++ as soon as you run the script if it’s not already open, then you would just put that part in the auto-execute section and leave the rest as it was before:

Code: Select all

#SingleInstance, Force
#Persistent
if !Winexist("ahk_exe notepad++.exe")
	Run, C:\Program Files (x86)\Notepad++\notepad++.exe
OnClipboardChange("ClipChanged")
return

Esc::
MsgBox BYE
ExitApp
	
ClipChanged() {
	ControlSend, Scintilla1, ^v`n, ahk_exe Notepad++.exe
}

I think I’ve determined that the above is what you meant. Please try to be more clear in your questions/requests. It would have been much clearer to say “I want the script to open Notepad++ if it’s not already open” than to say “The script works when Notepad++ is already open, but I also want it to work when it’s not open” (paraphrasing). Hopefully, you can see why.
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Please help me auto paste into Notepad++.

18 Mar 2022, 10:58

I put this in my Windows startup folder and now every time that I use the computer and the first time that I press Esc, I get the message box that is supposed to confirm accessing the script. should I put Esc and ExitApp between #IfWinActive and #If or what?
User avatar
boiler
Posts: 17279
Joined: 21 Dec 2014, 02:44

Re: Please help me auto paste into Notepad++.

18 Mar 2022, 12:31

I don’t understand why you’re saying it’s supposed to confirm accessing the script when you have it set up to exit the script, and you even precede it with a “BYE” message.
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Please help me auto paste into Notepad++.

18 Mar 2022, 12:36

I'm sorry about the mixup there, the message is supposed to confirm exit.
User avatar
boiler
Posts: 17279
Joined: 21 Dec 2014, 02:44

Re: Please help me auto paste into Notepad++.

18 Mar 2022, 14:06

So what isn’t it doing that you want it to do? Or what is it doing that you don’t want it to do?
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Please help me auto paste into Notepad++.

18 Mar 2022, 15:40

What it is doing that I don't want it to do is display the message when I press Esc.
User avatar
boiler
Posts: 17279
Joined: 21 Dec 2014, 02:44

Re: Please help me auto paste into Notepad++.

18 Mar 2022, 16:52

You don’t want to see the message that’s displayed by the MsgBox command? Can you at least take a guess on how you might make that happen?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ntepa and 122 guests