hotstring with userinput possible? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rfman112
Posts: 4
Joined: 14 May 2021, 17:35

hotstring with userinput possible?

Post by rfman112 » 14 May 2021, 18:02

Hey,

is in anyway possible to make a hotstring with a userinput, but with one word only?

anything like this

Code: Select all

::t (userinput(one word))::test hi
User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: hotstring with userinput possible?

Post by flyingDman » 14 May 2021, 18:47

Have a look at hotstrings here https://github.com/Paris/AutoHotkey-Scripts/blob/master/Hotstrings.ahk.

The example you gave seems to indicate that any word typed would result in sending "test hi". I do not see the use for that. But hotstrings can take this a lot further and is very powerful (though resource hungry; although I have not seen this being an issue). The following is an example:

Code: Select all

hotstrings("([a-z0-9]{3,6}_\s)","label")
return

label:
send % "You entered " $1
return
If you type a 3 to 6 letter word followed by a "_" it will send that word preceded by "You entered"
14.3 & 1.3.7
gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: hotstring with userinput possible?  Topic is solved

Post by gregster » 14 May 2021, 18:48

Another approach, which will take the word (a name in this case) and use it in the replacement string:

Code: Select all

:B0*:t ::
	input, var, V, {space}{enter}
	len := StrLen(var) + 3
	Sendinput {BS %len%}hello %var%, nice to meet you{!}
return
Typing t gregster (followed by a Space or Enter) will yield hello gregster, nice to meet you!.
rfman112
Posts: 4
Joined: 14 May 2021, 17:35

Re: hotstring with userinput possible?

Post by rfman112 » 15 May 2021, 02:15

gregster wrote:
14 May 2021, 18:48
Another approach, which will take the word (a name in this case) and use it in the replacement string:

Code: Select all

:B0*:t ::
	input, var, V, {space}{enter}
	len := StrLen(var) + 3
	Sendinput {BS %len%}hello %var%, nice to meet you{!}
return
Typing t gregster (followed by a Space or Enter) will yield hello gregster, nice to meet you!.
Thank you! This is what I'm searching for :D
Now is it also possible to disable a key from reading?
I mean the hotstring is "te test" and when I'm continously holding as example the key "W" the hotstring wont work, when i press directly, after releasing "W", te test. I think the script reads than "wte test" and thats why it not works. So could i disable "w" from reading before this? But the key "w" should work after this. So an example:

Pressing W (disabled), directly writing "te why" <- but here should the w again work inside the hotstring.

So in short: the first key is never "w" :?: :D
gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: hotstring with userinput possible?

Post by gregster » 15 May 2021, 06:42

Not sure, if I understand completely, but you can stack different hotstring variants:

Code: Select all

:B0*:wt ::
:B0*:t ::
	input, var, V, {space}{enter}
  	len := (StrLen(A_thishotkey) = 8) ? StrLen(var) + 4 : StrLen(var) + 3	; calculation could be generalized for more variants
	Sendinput {BS %len%}hello %var%, nice to meet you{!}
return
But obviously, w needs to be typed out first - since AHK can't tell the future... ;)
(or should the character w only be typed out after typing tspace and otherwise always be suppressed ? of course, that could be done
One approach:)
Spoiler

But if the hotstring should generally work in words, the ? option can help. (By default, hotstrings work only if they are at the start of a new word.)

For more complex or flexible situations, the Regex approach - mentioned by flyingDman above - might be better suited, or other clever solutions... ;)

original post has been modified
rfman112
Posts: 4
Joined: 14 May 2021, 17:35

Re: hotstring with userinput possible?

Post by rfman112 » 16 May 2021, 11:02

gregster wrote:
15 May 2021, 06:42
Not sure, if I understand completely, but you can stack different hotstring variants:

Code: Select all

:B0*:wt ::
:B0*:t ::
	input, var, V, {space}{enter}
  	len := (StrLen(A_thishotkey) = 8) ? StrLen(var) + 4 : StrLen(var) + 3	; calculation could be generalized for more variants
	Sendinput {BS %len%}hello %var%, nice to meet you{!}
return
But obviously, w needs to be typed out first - since AHK can't tell the future... ;)
(or should the character w only be typed out after typing tspace and otherwise always be suppressed ? of course, that could be done
One approach:)
Spoiler

But if the hotstring should generally work in words, the ? option can help. (By default, hotstrings work only if they are at the start of a new word.)

For more complex or flexible situations, the Regex approach - mentioned by flyingDman above - might be better suited, or other clever solutions... ;)

original post has been modified
yea this would work, but i want the key W just not to be registered as first key. Now its completly disabled :D
gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: hotstring with userinput possible?

Post by gregster » 16 May 2021, 11:09

What is your exact definition of a 'first key' ?
In which cases do you want to actually use the w key as itself, sending w ? Examples?
It sounds like you won't use it for words, but for a game ? Or, do you simply never use words like we, would, world, will and so on?
It could make sense to separate different scenarios by some criterion (tbd): In-game use vs. input-capable edit field/chat, or similar.
rfman112
Posts: 4
Joined: 14 May 2021, 17:35

Re: hotstring with userinput possible?

Post by rfman112 » 16 May 2021, 13:22

gregster wrote:
16 May 2021, 11:09
What is your exact definition of a 'first key' ?
In which cases do you want to actually use the w key as itself, sending w ? Examples?
It sounds like you won't use it for words, but for a game ? Or, do you simply never use words like we, would, world, will and so on?
It could make sense to separate different scenarios by some criterion (tbd): In-game use vs. input-capable edit field/chat, or similar.
ah sorry i understand.

yes for a game. I'm holding "W" and than i want to use the hotstring i created with "twd", but it wont work after i hold w. so the script thinks im pressing "wtwd" . At the moment i need to press space before i can use my hotstring.
Post Reply

Return to “Ask for Help (v1)”