HotStrings.ahk

Esta sección es para compartir scripts, librerías y herramientas.

Moderator: Flipeador

Scripting
Posts: 5
Joined: 08 Sep 2015, 01:17

HotStrings.ahk

14 Sep 2015, 19:32

Hola a todo el mundo, necesito a alguien que sepa el uso de la librería HotStrings.ahk publicada y modificada por Edd (http://www.autohotkey.com/board/topic/1 ... otstrings/) para que me aclare una duda. Gracias saludos!
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: HotStrings.ahk

14 Sep 2015, 20:29

Hola; ¿Que dudas tienes?.
He provado la version modificada por Edd, pero no parece funcionar; por lo menos a mi no, no en la ultima version de AutoHotKey (1.1.22.06).
La version original si me funciona:

Code: Select all

hotstrings("(B|b)tw\s", "%$1%y the way") ; type 'btw' followed by space, tab or return
/*
	Function: hotstrings
		Dynamically adds regular expression hotstrings.

	Parameters:
		c - regular expression hotstring
		a - (optional) text to replace hotstring with or a label to goto, 
			leave blank to remove hotstring definition from triggering an action

	Examples:
> hotstrings("(B|b)tw\s", "%$1%y the way") ; type 'btw' followed by space, tab or return
> hotstrings("i)omg", "oh my god{!}") ; type 'OMG' in any case, upper, lower or mixed
> hotstrings("\bcolou?r", "rgb(128, 255, 0);") ; '\b' prevents matching with anything before the word, e.g. 'multicololoured'

	License:
		- Version 2.54 <http://www.autohotkey.net/~Titan/#hotstrings>
		- Simplified BSD License <http://www.autohotkey.net/~Titan/license.txt>
*/
hotstrings(k, a = "")
{
	static z, m = "*~$", s, t, w = 2000
	global $
	If z = ; init
	{
		Loop, 94
		{
			c := Chr(A_Index + 32)
			If A_Index not between 33 and 58
				Hotkey, %m%%c%, __hs
		}
		e = BS|Space|Enter|Return|Tab
		Loop, Parse, e, |
			Hotkey, %m%%A_LoopField%, __hs
		z = 1
	}
	If (a == "" and k == "") ; poll
	{
		StringTrimLeft, q, A_ThisHotkey, StrLen(m)
		If q = BS
		{
			If (SubStr(s, 0) != "}")
				StringTrimRight, s, s, 1
		}
		Else
		{
			If q = Space
				q := " "
			Else If q = Tab
				q := "`t"
			Else If q in Enter,Return
				q := "`n"
			Else If (StrLen(q) != 1)
				q = {%q%}
			Else If (GetKeyState("Shift") or GetKeyState("CapsLock", "T"))
				StringUpper, q, q
			s .= q
		}
		Loop, Parse, t, `n ; check
		{
			StringSplit, x, A_LoopField, `r
			If (RegExMatch(s, x1 . "$", $)) ; match
			{
				StringLen, l, $
				StringTrimRight, s, s, l
				SendInput, {BS %l%}
				If (IsLabel(x2))
					Gosub, %x2%
				Else
				{
					Transform, x0, Deref, %x2%
					SendInput, %x0%
				}
			}
		}
		If (StrLen(s) > w)
			StringTrimLeft, s, s, w // 2
	}
	Else ; assert
	{
		StringReplace, k, k, `n, \n, All ; normalize
		StringReplace, k, k, `r, \r, All
		Loop, Parse, t, `n
		{
			l = %A_LoopField%
			If (SubStr(l, 1, InStr(l, "`r") - 1) == k)
				StringReplace, t, t, `n%l%
		}
		If a !=
			t = %t%`n%k%`r%a%
	}
	Return
	__hs: ; event
	hotstrings("", "")
	Return
}
Scripting
Posts: 5
Joined: 08 Sep 2015, 01:17

Re: HotStrings.ahk

15 Sep 2015, 14:34

Gracias por responder Flipeador! Estoy recién empezando a utilizar esta librería y no he podido entender su documentación ya que mi ingles es muy malo. Tal vez tu puedas ayudarme. La duda que tengo es como asignarle al segundo parámetro un bloque de texto. Ya he intentado esto:

var =
(
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
)
hotstrings("im)lorem", var)

Pero no funciona. Solo me escribe la primera línea.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: HotStrings.ahk

15 Sep 2015, 19:08

Parece ser que la funcion no permite el texto multilinea...
pero si solo quieres introducir ese texto al tipear imlorem, puedes usar algo como:

Code: Select all

;b0 = mantiene la palabra escrita, no la reemplaza.
;* = sin necesidad de un espacio.
:*b0:imlorem::
(
 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.`n
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.`n
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.`n
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
)
return
~Esc::ExitApp

Code: Select all

;b0 = mantiene la palabra escrita, no la reemplaza.
;* = sin necesidad de un espacio.
:*b0:imlorem::
SendInput, % " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.`n"
	. "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.`n"
	. "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.`n"
	. "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
return
~Esc::ExitApp
si quieres usar esa funcion, habria que intentar reescribirla usando un Array, tal vez...
Scripting
Posts: 5
Joined: 08 Sep 2015, 01:17

Re: HotStrings.ahk

15 Sep 2015, 20:11

Muchas gracias "Flipeador" Si me sirvió gracias.!
Edd
Posts: 42
Joined: 16 Aug 2014, 16:45

Re: HotStrings.ahk

29 Dec 2015, 03:27

Que version utilizas de autohotkey Flipeador? porque a mi me sigue funcionando perfectamente con la ultima version de autohotkey v1.1.22.09 unicode 32bits
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: HotStrings.ahk

29 Dec 2015, 06:30

Edd,
esto no me funciona:

Code: Select all

hotstrings("(B|b)tw\s", "%$1%y the way")

hotstrings(k, a = "", Options:="")
{
    static z, m = "~$", m_ = "*~$", s, t, w = 2000, sd, d = "Left,Right,Up,Down,Home,End,RButton,LButton", f = "!,+,^,#", f_="{,}"
    global $
    If z = ; init
    {
        RegRead, sd, HKCU, Control Panel\International, sDecimal
        Loop, 94
        {
            c := Chr(A_Index + 32)
            If A_Index between 33 and 58
                Hotkey, %m_%%c%, __hs
            else If A_Index not between 65 and 90
                Hotkey, %m%%c%, __hs
        }
        e = 0,1,2,3,4,5,6,7,8,9,Dot,Div,Mult,Add,Sub,Enter
        Loop, Parse, e, `,
            Hotkey, %m%Numpad%A_LoopField%, __hs
        e = BS,Shift,Space,Enter,Return,Tab,%d%
        Loop, Parse, e, `,
            Hotkey, %m%%A_LoopField%, __hs
        z = 1
    }
    If (a == "" and k == "") ; poll
    {
        q:=RegExReplace(A_ThisHotkey, "\*\~\$(.*)", "$1")
        q:=RegExReplace(q, "\~\$(.*)", "$1")
        If q = BS
        {
            If (SubStr(s, 0) != "}")
                StringTrimRight, s, s, 1
        }
        Else If q in %d%
            s =
        Else
        {
            If q = Shift
            return
            Else If q = Space
                q := " "
            Else If q = Tab
                q := "`t"
            Else If q in Enter,Return,NumpadEnter
                q := "`n"
            Else If (RegExMatch(q, "Numpad(.+)", n))
            {
                q := n1 == "Div" ? "/" : n1 == "Mult" ? "*" : n1 == "Add" ? "+" : n1 == "Sub" ? "-" : n1 == "Dot" ? sd : ""
                If n1 is digit
                    q = %n1%
            }
            Else If (GetKeyState("Shift") ^ !GetKeyState("CapsLock", "T"))
                StringLower, q, q
            s .= q
        }
        Loop, Parse, t, `n ; check
        {
            StringSplit, x, A_LoopField, `r
            If (RegExMatch(s, x1 . "$", $)) ; match
            {
                StringLen, l, $
                StringTrimRight, s, s, l
                if !(x3~="i)\bNB\b")        ; if No Backspce "NB"
                    SendInput, {BS %l%}
                If (IsLabel(x2))
                    Gosub, %x2%
                Else
                {
                    Transform, x0, Deref, %x2%
                    Loop, Parse, f_, `,
                        StringReplace, x0, x0, %A_LoopField%, ¥%A_LoopField%¥, All
                    Loop, Parse, f_, `,
                        StringReplace, x0, x0, ¥%A_LoopField%¥, {%A_LoopField%}, All
                    Loop, Parse, f, `,
                        StringReplace, x0, x0, %A_LoopField%, {%A_LoopField%}, All
                    SendInput, %x0%
                }
            }
        }
        If (StrLen(s) > w)
            StringTrimLeft, s, s, w // 2
    }
    Else ; assert
    {
        StringReplace, k, k, `n, \n, All ; normalize
        StringReplace, k, k, `r, \r, All
        Loop, Parse, t, `n
        {
            l = %A_LoopField%
            If (SubStr(l, 1, InStr(l, "`r") - 1) == k)
                StringReplace, t, t, `n%l%
        }
        If a !=
            t = %t%`n%k%`r%a%`r%Options%
    }
    Return
    __hs: ; event
    hotstrings("", "", Options)
    Return
}
escribo "btw" y preciono "enter, escape, tab..." pero no hace nada.

Utilizo la última versión.
Además de que no permite texto multilinea.
Edd
Posts: 42
Joined: 16 Aug 2014, 16:45

Re: HotStrings.ahk

29 Dec 2015, 18:01

Es por el parametro "/s" (Any whitespace character) funcionaria sin el parametro "/s"

Y este ejemplo es para que no importe si hay espacio entre cada caracter: hotstrings("(B|b)\s*t\s*w", "%$1%y the way")

Del texto multilinea es cierto, talvez mas adelante le haga un fix.
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: HotStrings.ahk

29 Dec 2015, 18:49

pues a mi no me funciona.
si quieres pon un ejemplo, y dime que tengo que escribir para probarlo.
Edd
Posts: 42
Joined: 16 Aug 2014, 16:45

Re: HotStrings.ahk

29 Dec 2015, 19:22

Code: Select all

hotstrings("(B|b)tw", "%$1%y the way")

Gui, Add, Edit, w300 h100
Gui, Show
Return

GuiEscape:
GuiClose:
ExitApp

hotstrings(k, a = "", Options:="")
{
    static z, m = "~$", m_ = "*~$", s, t, w = 2000, sd, d = "Left,Right,Up,Down,Home,End,RButton,LButton", f = "!,+,^,#", f_="{,}"
    global $
    If z = ; init
    {
        RegRead, sd, HKCU, Control Panel\International, sDecimal
        Loop, 94
        {
            c := Chr(A_Index + 32)
            If A_Index between 33 and 58
                Hotkey, %m_%%c%, __hs
            else If A_Index not between 65 and 90
                Hotkey, %m%%c%, __hs
        }
        e = 0,1,2,3,4,5,6,7,8,9,Dot,Div,Mult,Add,Sub,Enter
        Loop, Parse, e, `,
            Hotkey, %m%Numpad%A_LoopField%, __hs
        e = BS,Shift,Space,Enter,Return,Tab,%d%
        Loop, Parse, e, `,
            Hotkey, %m%%A_LoopField%, __hs
        z = 1
    }
    If (a == "" and k == "") ; poll
    {
        q:=RegExReplace(A_ThisHotkey, "\*\~\$(.*)", "$1")
        q:=RegExReplace(q, "\~\$(.*)", "$1")
        If q = BS
        {
            If (SubStr(s, 0) != "}")
                StringTrimRight, s, s, 1
        }
        Else If q in %d%
            s =
        Else
        {
            If q = Shift
            return
            Else If q = Space
                q := " "
            Else If q = Tab
                q := "`t"
            Else If q in Enter,Return,NumpadEnter
                q := "`n"
            Else If (RegExMatch(q, "Numpad(.+)", n))
            {
                q := n1 == "Div" ? "/" : n1 == "Mult" ? "*" : n1 == "Add" ? "+" : n1 == "Sub" ? "-" : n1 == "Dot" ? sd : ""
                If n1 is digit
                    q = %n1%
            }
            Else If (GetKeyState("Shift") ^ !GetKeyState("CapsLock", "T"))
                StringLower, q, q
            s .= q
        }
        Loop, Parse, t, `n ; check
        {
            StringSplit, x, A_LoopField, `r
            If (RegExMatch(s, x1 . "$", $)) ; match
            {
                StringLen, l, $
                StringTrimRight, s, s, l
                if !(x3~="i)\bNB\b")        ; if No Backspce "NB"
                    SendInput, {BS %l%}
                If (IsLabel(x2))
                    Gosub, %x2%
                Else
                {
                    Transform, x0, Deref, %x2%
                    Loop, Parse, f_, `,
                        StringReplace, x0, x0, %A_LoopField%, ¥%A_LoopField%¥, All
                    Loop, Parse, f_, `,
                        StringReplace, x0, x0, ¥%A_LoopField%¥, {%A_LoopField%}, All
                    Loop, Parse, f, `,
                        StringReplace, x0, x0, %A_LoopField%, {%A_LoopField%}, All
                    SendInput, %x0%
                }
            }
        }
        If (StrLen(s) > w)
            StringTrimLeft, s, s, w // 2
    }
    Else ; assert
    {
        StringReplace, k, k, `n, \n, All ; normalize
        StringReplace, k, k, `r, \r, All
        Loop, Parse, t, `n
        {
            l = %A_LoopField%
            If (SubStr(l, 1, InStr(l, "`r") - 1) == k)
                StringReplace, t, t, `n%l%
        }
        If a !=
            t = %t%`n%k%`r%a%`r%Options%
    }
    Return
    __hs: ; event
    hotstrings("", "", Options)
    Return
}
Eso deberia de funcionarte
Edd
Posts: 42
Joined: 16 Aug 2014, 16:45

Re: HotStrings.ahk

29 Dec 2015, 21:13

Me parece muy extraño, lo probare en otras pc's lo eh probado en 2 hasta ahora y en las dos me funciona bien
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: HotStrings.ahk

30 Dec 2015, 07:34

perdón, pero acabo de darme cuenta que el problema me lo estaba dando SciTE, pero guardando el archivo pude hacerlo funcionar. funciona perfecto.
Image
Edd
Posts: 42
Joined: 16 Aug 2014, 16:45

Re: HotStrings.ahk

30 Dec 2015, 14:05

Ok, gracias por informarme.

Return to “Scripts y Funciones”

Who is online

Users browsing this forum: No registered users and 18 guests