RegExHotstring - dynamic RegEx Hotstrings

Post your working scripts, libraries and tools.
oldstone
Posts: 13
Joined: 28 Oct 2021, 07:29

Re: RegExHotstring - dynamic RegEx Hotstrings

05 Feb 2024, 03:53

If it can support '# IfWin' and '# HotIf', it will be more powerful and practical. Eagerly anticipating。
8LWXpg
Posts: 46
Joined: 26 May 2022, 03:55

Re: RegExHotstring - dynamic RegEx Hotstrings

05 Feb 2024, 06:39

oldstone wrote:
05 Feb 2024, 03:53
If it can support '# IfWin' and '# HotIf', it will be more powerful and practical. Eagerly anticipating。
This is because there's no general API to work with #HotIf in AutoHotkey. It will only work if AutoHotkey supports it in a future update.
fmoon
Posts: 2
Joined: 09 Feb 2024, 12:08

Re: RegExHotstring() dynamic RegEx Hotstrings

09 Feb 2024, 12:28

Hello,
I can't trigger the RegEX if it containts more than one word.
for exemple I want to tringer it when ever I type @Robot commande param1 param2 , it shoud execute the commande function with param1, param2

Code: Select all

RegExHotstring("@Robot\s(commande)\s(param1)\s(param2) /t}", commande , "C*") ; the trigger can be space or tabulation. 
@8LWXpg , can you help make it work?

Thank your for your support.
8LWXpg wrote:
23 Feb 2023, 08:35
frabjous wrote:
20 Feb 2023, 16:25
This script is excellent but I am having trouble creating a dynamic hotstring which is triggered by either a space or a punctuation mark at the end of the entered text. I thought I could do this with the recently added "no end key" option and including the punctuation marks in the hotstring (along the lines "[.,;: ]") but then I cannot make it work when a space is typed. Am I missing something?
current work around is to make two separate hotstrings, one take "[.,;:]" at the end and use "*" option, another doesn't.
8LWXpg
Posts: 46
Joined: 26 May 2022, 03:55

Re: RegExHotstring() dynamic RegEx Hotstrings

09 Feb 2024, 23:05

fmoon wrote:
09 Feb 2024, 12:28
Hello,
I can't trigger the RegEX if it containts more than one word.
for exemple I want to tringer it when ever I type @Robot commande param1 param2 , it shoud execute the commande function with param1, param2

Code: Select all

RegExHotstring("@Robot\s(commande)\s(param1)\s(param2) /t}", commande , "C*") ; the trigger can be space or tabulation. 
@8LWXpg , can you help make it work?

Thank your for your support.
as said in the readme, it's unable to match white space characters.
AladdinMhemed
Posts: 13
Joined: 09 Jan 2019, 16:52

Re: RegExHotstring - dynamic RegEx Hotstrings

25 Feb 2024, 00:48

is there an option to cancel the replacement on a condition in the callback?
for example

Code: Select all

rand(match) {
        if (match[0] != 'aaa') {
           ; cancel and don't replace and return
        } 
	static char := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	static char_len := StrLen(char)
	loop match[1] {
		r := Random(1, char_len)
		str .= SubStr(char, r, 1)
	}
	SendText(str)
}
8LWXpg
Posts: 46
Joined: 26 May 2022, 03:55

Re: RegExHotstring - dynamic RegEx Hotstrings

25 Feb 2024, 04:41

AladdinMhemed wrote:
25 Feb 2024, 00:48
is there an option to cancel the replacement on a condition in the callback?
You have two ways:
  • Catch the trigger string and send it back.
  • Use the B0 option to suppress the trigger string remove, then send backspace characters equal to the length of the trigger string, followed by the replace string.
Jasonosaj
Posts: 58
Joined: 02 Feb 2022, 15:02
Location: California

Re: RegExHotstring - dynamic RegEx Hotstrings

26 Feb 2024, 11:30

Alright, Ladies and Gents: how's everyone using this? Great function, by the way!
User avatar
Chrysalis
Posts: 13
Joined: 09 Feb 2021, 19:04

Re: RegExHotstring - dynamic RegEx Hotstrings

19 May 2024, 15:15

@8LWXpg
Generally nice script, but it breaks all applications that rely on pressing and holding any of the a-z keys (especially games, i.e. Minecraft).

With an active script that uses RegExHotstring command, try using WASD to move in this online Minecraft schematic viewer cubical.xyz. Then exit that script and try moving again - you'll see that movement works as expected.

My question: is it possible to somehow not break the press and hold functionality?
User avatar
Chrysalis
Posts: 13
Joined: 09 Feb 2021, 19:04

Re: RegExHotstring - dynamic RegEx Hotstrings

22 May 2024, 12:16

Thanks for fast reply, but after updating and running a simple script that includes RegExHotstring and normal Hotstrings an error occurs.
Error:
Image
Script:

Code: Select all

#Requires AutoHotkey >=2.0-
#SingleInstance Force

#Include "RegExHotstring.ahk"

^+Ins::ExitApp

::abc::cba

RegHook.MinSendLevel := 2
SendLevel(1)

RegExHotstring("([A-Z])([A-Z])([a-z]+)", "$1$L2$3", "TC")
Run the script and then press anything and you'll get this error. I have AutoHotkey v2.0.15 installed.
8LWXpg
Posts: 46
Joined: 26 May 2022, 03:55

Re: RegExHotstring - dynamic RegEx Hotstrings

22 May 2024, 23:25

Fixed SendLevel in function OnKeyUp
Fixed bug in option * with B0

https://github.com/8LWXpg/RegExHotstring/releases/tag/v5.2
User avatar
Chrysalis
Posts: 13
Joined: 09 Feb 2021, 19:04

Re: RegExHotstring - dynamic RegEx Hotstrings

24 May 2024, 08:39

Again thanks for a fast reply. I came to report further errors. So in Minecraft (and many other games) a very common thing to do is to press any of the WSAD move keys and while pressing them press Space to jump. Unfortunately if you do this while the script is running you get stuck walking in the direction you were walking even if you release all WSAD keys and Space. You can test it yourself on the cubical site.
8LWXpg
Posts: 46
Joined: 26 May 2022, 03:55

Re: RegExHotstring - dynamic RegEx Hotstrings

25 May 2024, 05:52

The current implementation has a problem with properly catching and sending the 'key up' event, which I have not found a good workaround yet.
https://github.com/8LWXpg/RegExHotstring/issues/9

I've created a branch that does not suppress text keys. This may be slightly jankier if the cursor moves within the Callback, but it reduces the need for workarounds.
https://github.com/8LWXpg/RegExHotstring/tree/no_suppress_text
User avatar
Chrysalis
Posts: 13
Joined: 09 Feb 2021, 19:04

Re: RegExHotstring - dynamic RegEx Hotstrings

25 May 2024, 08:36

Yeah, I thought that my last post was too much for such script. Nevertheless - this is very good script. You still managed to get it working for simple gameplay usage where you don't have to jump while walking and make it work with other normal hotstrings in the same file. Much thanks for that. But I'll have to disable this script for games. I know that current limitation is that it is "incompatible with #IfWin or #HotIf". But is there a hard way solution? Like setting up a listener that would run every time the active window changes and (un)registers RegExHotstrings for certain windows?

I know that this would require me to make a list of all games' WinTitles and check this list on every window change but I'm willing to do this.
8LWXpg
Posts: 46
Joined: 26 May 2022, 03:55

Re: RegExHotstring - dynamic RegEx Hotstrings

25 May 2024, 09:21

As I said before,
8LWXpg wrote:
05 Feb 2024, 06:39
oldstone wrote:
05 Feb 2024, 03:53
If it can support '# IfWin' and '# HotIf', it will be more powerful and practical. Eagerly anticipating。
This is because there's no general API to work with #HotIf in AutoHotkey. It will only work if AutoHotkey supports it in a future update.
However, if you manage to invoke a function at every window focus change, you can disable the InputHook used by RegExHotString, this would stop all the RegExHotString.

Code: Select all

RegHook.Stop()
And for the bug, the script in the branch should fix the bug, just slightly jankier if the cursor moves within the Callback (like Send("{Left 3}")).
User avatar
Chrysalis
Posts: 13
Joined: 09 Feb 2021, 19:04

Re: RegExHotstring — dynamic RegEx Hotstrings

25 May 2024, 14:41

8LWXpg wrote: However, if you manage to invoke a function at every window focus change
I did. It was surprisingly easy. All I had to do was to add this at the end of the script, that I've posted previously:

Code: Select all

GroupAdd "Games", "Minecraft ahk_exe javaw.exe"
; ... more games to be added here

Loop {
	If (WinActive("ahk_group Games")) {
		RegHook.Stop()
	} else {
		RegHook.Start()
	}
	WinWaitNotActive WinExist("A") ; This does the trick
}
So for anyone stumbling upon this thread in the future, this is the whole correctly working template script with normal Hotstrings and RegExHotstrings that are conditionally disabled for certain windows:

Code: Select all

#Requires AutoHotkey >=2.0-
#SingleInstance Force

#Include "RegExHotstring.ahk"

^+Ins::ExitApp

::youre::you're

RegHook.MinSendLevel := 2
SendLevel(1)

RegExHotstring("([A-Z])([A-Z])([a-z]+)", "$1$L2$3", "TC")

GroupAdd "Games", "Minecraft ahk_exe javaw.exe"
; ... more games/programs to be added here

Loop {
	If (WinActive("ahk_group Games")) {
		RegHook.Stop()
	} else {
		RegHook.Start()
	}
	WinWaitNotActive WinExist("A")
}
Cheers! ; )
User avatar
Chrysalis
Posts: 13
Joined: 09 Feb 2021, 19:04

Re: RegExHotstring - dynamic RegEx Hotstrings

06 Jun 2024, 05:43

OK, I've tested this new version and I can gladly say it works in Minecraft (and some other games). Great job! :clap:

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: Spikea and 17 guests