Newbie Help with Hotstring

Get help with using AutoHotkey and its commands and hotkeys
Kenn_Guilstorf
Posts: 4
Joined: 20 Jun 2019, 08:49

Newbie Help with Hotstring

20 Jun 2019, 10:01

I've a problem with a hotstring. What I'm trying to do is 'write' a pseudo-XML tag into a web form. This is what I'm looking for:
<comment author="abcd">

</comment>
with the carat left on the blank line between the beginning and ending comment tag. Here's my hotstring:

Code: Select all

:*b0t0:<c*::{bs}omment author="abcd">{enter 2}<\comment>{enter}{left 12}
Here's what I USUALLY end up with (sometimes, the 'blank line' shifts to AFTER the closing comment tag):
<omment author="abcd">

<\comment>
c

and the carat is left at the beginning of the closing <\comment> line. I've experimented with changing the SendMode from Input to Event, adding k99 to the b0t0 and even adding {sleep, 500} before each of the different 'keystroke' commands. I can mess it up worse but I can't get to what I'm trying. Anyone know what I'm doing wrong? (Longer explanation below)

The whole story is I'm using a modified script I found on the internet to load two different scripts. Here's the MasterScript:

Code: Select all

======================
; Master AHK Script
; Modified from https://autohotkey.com/board/topic/5119-launching-multiple-ahk-scripts/
; ----- Common Settings -----
#SingleInstance force
StringCaseSense On

; ----- AutoExecute commands -----
;...

; ----- Included Scripts -----
GoSub WebformSetup
GoSub AutoCorrectSetup
GoTo Shared

AutoCorrectSetup:
#include c:\tools\ahk_scripts\AutoCorrect.ahk
Return

WebformSetup:
#include c:\tools\ahk_scripts\Webform.ahk
Return

Shared:
; ----- Shared subroutines, functions ---
====================
Here's the full Webform.ahk:

Code: Select all

====================
;#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
;SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
;SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
OldSendMode := A_SendMode
SendMode Event


; ----- Hotstrings -----
#IfWinActive PROG
:*b0t0:<t*::{sleep, 500}{bs}itle author="abcd"><\title>{sleep, 500}{left 8}
:*b0t0:<c*::{bs}omment author="abcd">{enter 2}<\comment>{enter}{left 12}

SetKeyDelay -1
SendMode %OldSendMode%
====================
I didn't include the 'autocorrect.ahk' because it's the 'normal' autocorrect script I downloaded from autohotkey.com. If I run JUST the webform.ahk, I get closer - but it looks like the {enter 2} is completely ignored because both of the comment tags are on the same line and the carat is left just after the opening brace in the closing comment tag.

Notice I do similar things for <t* and <c* - but <t* actually works...and the only difference I can see is the '{enter 2}'...

Moderator Note: Added code tags. ~ sinkfaze
User avatar
sinkfaze
Posts: 609
Joined: 01 Oct 2013, 08:01

Re: Newbie Help with Hotstring

20 Jun 2019, 10:09

I think eliminating the automatic backspacing is unnecessary, just adds complexity to what you're trying to do.

This works fine for me.

Code: Select all

:*t0:<c*::<comment author="abcd">{ENTER 2}</comment>{ENTER}{HOME}{UP 2}
Kenn_Guilstorf
Posts: 4
Joined: 20 Jun 2019, 08:49

Re: Newbie Help with Hotstring

20 Jun 2019, 10:30

sinkfaze wrote:
20 Jun 2019, 10:09
I think eliminating the automatic backspacing is unnecessary, just adds complexity to what you're trying to do.

This works fine for me.

Code: Select all

:*t0:<c*::<comment author="abcd">{ENTER 2}</comment>{ENTER}{HOME}{UP 2}
I'm not sure why, but that didn't work - it actually made it worse. I thought perhaps the problem was in the MasterScript.ahk (or something it was loading) so I killed it and just ran the webform.ahk. The form I was working in was populated with:
...data...
<folder name="messages">

</folder>

And, after writing hitting enter a few times to give it room, I ended up with:
<folder name="messages">

</folder>

mment author="abcd">


co
<<

It then jumped to a completely different section of hte web page!
User avatar
sinkfaze
Posts: 609
Joined: 01 Oct 2013, 08:01

Re: Newbie Help with Hotstring

20 Jun 2019, 10:54

Try this instead:

Code: Select all

:*t0:<c*::
(
<comment author="abcd">

</comment>

)
Sleep, 25
Send {HOME}{UP 2}
return
Beyond that, you're going to have to experiment with the Send modes and key delays, because the receiving program is causing the problem.
Kenn_Guilstorf
Posts: 4
Joined: 20 Jun 2019, 08:49

Re: Newbie Help with Hotstring

20 Jun 2019, 11:22

sinkfaze wrote:
20 Jun 2019, 10:54
Try this instead:

Code: Select all

:*t0:<c*::
(
<comment author="abcd">

</comment>

)
Sleep, 25
Send {HOME}{UP 2}
return
Beyond that, you're going to have to experiment with the Send modes and key delays, because the receiving program is causing the problem.
That comes the absolute closest to what I want. It leaves the carat at the end (i.e., isn't interpreting the Send keys) but I can live with it. I don't doubt the problem is in the webform - this application is wonky even on good days.

Thanks for all the help!!

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], MannyKSoSo and 205 guests