Luis Diaz
asked on
AutoHotkey: move the cursor based on string
Hello experts,
I have the following AutoHotkey which allows me to send a comment block:
if you have questions, please contact me.
Thank you for your help.
I have the following AutoHotkey which allows me to send a comment block:
:*:blc::
FormatTime,CurrentDateTime3,,yyyy/MM/dd HH:mm:ss
If ((WinActive("ahk_exe excel.exe")) or (WinActive("ahk_exe vbsedit.exe")))
CommentBlock:="' *************************************************************************`n"
. "' Author: `n"
. "' Creation date: " . CurrentDateTime3 . "`n"
. "' Description:`n"
. "' ***************************************************************************`n"
Else
If (WinActive("ahk_exe notepad++.exe"))
CommentBlock:="Rem ======================================================================`n"
. "Rem Author: `n"
. "Rem Creation date: " . CurrentDateTime3 . "`n"
. "Rem Description:`n"
. "Rem ======================================================================`n"
Else
If (WinActive("ahk_exe powershell_ise.exe"))
CommentBlock:="# ===========================================================================`n"
. "# Author: `n"
. "# Creation date: " . CurrentDateTime3 . "`n"
. "# Description:`n"
. "# ===========================================================================`n"
Else
If (WinActive("ahk_exe sciTE.exe"))
CommentBlock:=";====================================`n"
. ";`n"
. ";====================================`n"
Else
If (WinActive("ahk_exe ssms.exe"))
CommentBlock:="-- ===========================================================================`n"
. "-- Author: `n"
. "-- Creation date: " . CurrentDateTime3 . "`n"
. "-- Description:`n"
. "-- ===========================================================================`n"
Else
{
MsgBox,4144,Error,Active window is not a supported program
Return
}
SendRaw %CommentBlock%
Return
I would like to put the cursor at the end of description for all the process which contain description string at comment block and to the beginning of second line for sciTE.exe which doesn't contain description string.if you have questions, please contact me.
Thank you for your help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Bill.
To be honest with you I don't know how to set the flag as recommended.
To be honest with you I don't know how to set the flag as recommended.
Hi Luis,
I've been AFK for a while and in case Bill is now, I'll jump in. You don't actually need the flag mechanism, because there will always be a non-null CommentBlock when you reach the SendRaw (due to the Return in the Else path above it). So it is safe to put your Up 2 AutoHotkey code right after the SendRaw...CommentBlock (and, thus, Description) will never be null at that point. Regards, Joe
I've been AFK for a while and in case Bill is now, I'll jump in. You don't actually need the flag mechanism, because there will always be a non-null CommentBlock when you reach the SendRaw (due to the Return in the Else path above it). So it is safe to put your Up 2 AutoHotkey code right after the SendRaw...CommentBlock (and, thus, Description) will never be null at that point. Regards, Joe
ASKER
Thank you Joe.
So it is safe to put your Up 2 AutoHotkey code right after the SendRaw...CommentBlockWithout a sleep prior the sendraw or can I put an sleep without an issue?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Noted. Thank you.
You're welcome, Luis, happy to help. Regards, Joe
ASKER
Another approach will be to avoid searching a string a send directly the keys since you know that the position will be the same no matter the application in which you send the %CommentBlock%.
I was thinking to do like this:
Open in new window
I tested in the various applications and it works.However I would like to have an expert advice on this.
Thank you for your help.