Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Autohotkey: open notepad++ and send ctrl+n

Hello experts,
I have the following command that allows me to open notepad ++.
I was wondering how to send ctrl + n to open a new tab as notepad ++ stock previous tab.
I tried the following but it doesn't work.
Thank you in advance for your help.
#!n:: Run C:\Program Files\Notepad++\notepad++.exe
Sleep 20
#IfWinActive ahk_class Notepad
Send, ^n

Open in new window

Thank you in advance for your help.
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Here's an AutoHotkey script that does it:

SetTitleMatchMode,2 ; contains
#!n::
Run C:\Program Files\Notepad++\notepad++.exe
WinWaitActive,Notepad++
Send ^n
Return

Open in new window

Regards, Joe
Avatar of Luis Diaz

ASKER

Thank you very much. I tested but I don't get the ctrl + n this is very strange.
Probably the activate windows is not notepad this is why the send  ctrl  + n is not performed.
Thank you very much for your help.
I suspect you're doing something wrong, as it works perfectly here every time. Does NPP run? Please post the script you're using.

P.S. I'm going to be afk for a couple of hours. Will check back into the thread as soon as I return to see how you're doing.
Thank you,
Unable to test it right now. I will keep you informed as soon as I can.
OK, I'm back...ready to help.
Avatar of Bill Prew
Bill Prew

You can also do this with VBS, even if you just want to test it to make sure NP++ is working as expected on your system.  Create the following VBS script and then run from a command line as below, after adjusting the path to your notepad++.exe as needed.

cscript np.vbs

Const NotepadPlusExe = "C:\Program Files\Notepad++\notepad++.exe"
With WScript.CreateObject("WScript.Shell")
    .Run NotepadPlusExe, 9
    WScript.Sleep 1000
    .SendKeys "^n"
End With

Open in new window


»bp
ASKER CERTIFIED SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tested and it cover the need. Thank you very much for your help!!
You're very welcome, Luis, I'm glad that works for you. Regards, Joe