Dynamic Hotstrings

Post your working scripts, libraries and tools for AHK v1.1 and older
Guest

Re: Dynamic Hotstrings

17 Mar 2015, 04:27

What is the purpose of (?i) If you really want to match max only try Hotstring("\b(MAX|max)(\d)(\d)\s","expand2",3)
nestit

Re: Dynamic Hotstrings

27 Jun 2016, 05:10

How can I apply keydelay ?
Guest

Re: Dynamic Hotstrings

27 Jun 2016, 07:55

If you replace the "SendInput" that occurs twice in the function with a Send, you can probably use SendMode and apply https://autohotkey.com/docs/commands/SetKeyDelay.htm
Note: SetKeyDelay is not obeyed by SendInput; there is no delay between keystrokes in that mode. This same is true for Send when SendMode Input is in effect.
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Dynamic Hotstrings

04 Jul 2016, 04:50

It was mentioned earlier but I did not understand if it was possible to use hotstrings and single key hotkeys in the same windows?

If I for example wanted the dynamic hotstrings and single key hotkeys to only work in notepad ?
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Dynamic Hotstrings

05 Jul 2016, 03:46

I just noticed that this does not work either:

Code: Select all

SetTimer, wincheck, 500
 
wincheck:
IfWinActive, ahk_class ConsoleWindowClass
    SetCapsLockState, On
else
    SetCapsLockState, Off
return
If I put it on top it works but the dynamic hotstrings does not. And if I put it below the dynamic hotstrings, the hotstrings work but not the SetTimer.
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Dynamic Hotstrings

05 Jul 2016, 04:01

Put

Code: Select all

SetTimer, wincheck, 500
on top and insert

Code: Select all

wincheck:
IfWinActive, ahk_class ConsoleWindowClass
    SetCapsLockState, On
else
    SetCapsLockState, Off
return
at the bottom of your script.

Related: FAQ: Why do some lines in my script never execute?
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Dynamic Hotstrings

05 Jul 2016, 04:48

Thanks, that solved the SetTimer part but are there any solution for the other problem where the dynamic-hotstrings are disabeling all my single key hotkeys?
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Dynamic Hotstrings

05 Jul 2016, 10:39

You can't have duplicate hotkeys in the same script. So your best option would be to run the hotstrings as a separate script. You could even store them in the same script and run as a second process using ExecScript(). Alternatively, the hotstring script would have to implement its own hook, which becomes annoying for special characters.
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Dynamic Hotstrings

06 Jul 2016, 00:32

How would I use the ExecScript method in this script?

Code: Select all

;-----Dynamic Hotstrings---------------
; download it from here https://github.com/menixator/ahk-repo/blob/master/Hotstring/Hotstring.ahk

Hotstring("([A-O]{2})(\d)(\d)([012])\s","expand2",3)
Hotstring("(MAX|FRASSE)(\d)(\d)\s","expand1",3)
Hotstring("(\b[A-O])(\d)(\d)([012])\s","expand3",3)
Hotstring("(FRASSE)(\d)(\d)([12])\s","expand4",3)
Hotstring("(\b\d{2,3})\s","expand5",3)
return 

::655105::30140162
::711182::10003563
::711195::10003568

;-----Hotkeys-------------------------------------

F5::
Send something
return

Space::
sendInput ^g{enter 2}
return

;----Subs for Dynamic hotstrings-------------------

Expand1:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER 3}"
}
else{
Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER}^kBOX{ENTER}" 
}

}
Return
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Dynamic Hotstrings

06 Jul 2016, 06:18

This won't run until you include your FileTail function. Basically all of the hotstring code is put inside a variable and not executed by the process you start. The contents of the variable are passed to a second instance of AutoHotkey, using a separate hook.

One thing to take into account; the child process will not exit when closing or restarting the parent process. Restarting the parent will invoke a second child process, so there will be two hotstring scripts running. However the old instance will now be processed after the newest and parent process, this may result in odd behavior.

Code: Select all

script=
(%`
		Menu,Tray,Tip,Hotstrings
		;-----Dynamic Hotstrings---------------
		; download it from here https://github.com/menixator/ahk-repo/blob/master/Hotstring/Hotstring.ahk
		 
		Hotstring("([A-O]{2})(\d)(\d)([012])\s","expand2",3)
		Hotstring("(MAX|FRASSE)(\d)(\d)\s","expand1",3)
		Hotstring("(\b[A-O])(\d)(\d)([012])\s","expand3",3)
		Hotstring("(FRASSE)(\d)(\d)([12])\s","expand4",3)
		Hotstring("(\b\d{2,3})\s","expand5",3)
		return 

		::655105::30140162
		::711182::10003563
		::711195::10003568

		;----Subs for Dynamic hotstrings-------------------
		 
		Expand1:
		{
		placeholder2 = qwe ;% FileTail("c:\test\test.log", 8)
		FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")
		 
		if(FoundPos != 0){
		Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER 3}"
		}
		else{
		Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER}^kBOX{ENTER}" 
		}
		 
		}
		Return

		Hotstring(trigger, label, mode := 1, clearTrigger := 1, cond := ""){
		global $
		static keysBound := false,hotkeyPrefix := "~$", hotstrings := {}, typed := "", keys := {"symbols": "!""#$%&'()*+,-./:;<=>?@[\]^_``{|}~", "num": "0123456789", "alpha":"abcdefghijklmnopqrstuvwxyz", "other": "BS,Return,Tab,Space", "breakKeys":"Left,Right,Up,Down,Home,End,RButton,LButton,LControl,RControl,LAlt,RAlt,AppsKey,Lwin,Rwin,WheelDown,WheelUp,f1,f2,f3,f4,f5,f6,f7,f8,f9,f6,f7,f9,f10,f11,f12", "numpad":"Numpad0,Numpad1,Numpad2,Numpad3,Numpad4,Numpad5,Numpad6,Numpad7,Numpad8,Numpad9,NumpadDot,NumpadDiv,NumpadMult,NumpadAdd,NumpadSub,NumpadEnter"}, effect := {"Return" : "`n", "Tab":A_Tab, "Space": A_Space, "Enter":"`n", "Dot": ".", "Div":"/", "Mult":"*", "Add":"+", "Sub":"-"}
		if (!keysBound){
		;Binds the keys to watch for triggers.
		for k,v in ["symbols", "num", "alpha"]
		{
		;alphanumeric/symbols
		v := keys[v]
		Loop,Parse, v
		Hotkey,%hotkeyPrefix%%A_LoopField%,__hotstring
		}
		v := keys.alpha
		Loop,Parse, v
		Hotkey, %hotkeyPrefix%+%A_Loopfield%,__hotstring
		for k,v in ["other", "breakKeys", "numpad"]
		{
		;comma separated values
		v := keys[v]
		Loop,Parse, v,`,
		Hotkey,%hotkeyPrefix%%A_LoopField%,__hotstring
		}
		keysBound := true ;keysBound is a static varible. Now, the keys won't be bound twice.
		}
		if (mode == "CALLBACK"){
		; Callback for the hotkey.s
		Hotkey := SubStr(A_ThisHotkey,3)
		if (StrLen(Hotkey) == 2 && Substr(Hotkey,1,1) == "+" && Instr(keys.alpha, Substr(Hotkey, 2,1))){
		Hotkey := Substr(Hotkey,2)
		if (!GetKeyState("Capslock", "T")){
		StringUpper, Hotkey,Hotkey
		}
		}
		shiftState := GetKeyState("Shift", "P")
		uppercase := GetKeyState("Capslock", "T") ? !shiftState : shiftState
		;If capslock is down, shift's function is reversed.(ie pressing shift and a key while capslock is on will provide the lowercase key)
		if (uppercase && Instr(keys.alpha, Hotkey)){
		StringUpper, Hotkey,Hotkey
		}
		if (Instr("," . keys.breakKeys . ",", "," . Hotkey . ",")){
		typed := ""
		return
		} else if Hotkey in Return,Tab,Space
		{
		typed .= effect[Hotkey]
		} else if (Hotkey == "BS"){
		; trim typed var if Backspace was pressed.
		StringTrimRight,typed,typed,1
		return
		} else if (RegExMatch(Hotkey, "Numpad(.+?)", numKey)) {
		if (numkey1 ~= "\d"){
		typed .= numkey1
		} else {
		typed .= effect[numKey1]
		}
		} else {
		typed .= Hotkey
		}
		matched := false
		for k,v in hotstrings
		{
		matchRegex := (v.mode == 1 ? "Oi)" : "") . (v.mode == 3 ? RegExReplace(v.trigger, "\$$", "") : "\Q" . v.trigger . "\E") . "$"
		if (v.mode == 3){
		if (matchRegex ~= "^[^\s\)\(\\]+?\)"){
		matchRegex := "O" . matchRegex
		} else {
		matchRegex := "O)" . matchRegex
		}
		}
		if (RegExMatch(typed, matchRegex, local$)){
		matched := true
		if (v.cond != "" && IsFunc(v.cond)){
		; If hotstring has a condition function.
		A_LoopCond := Func(v.cond)
		if (A_LoopCond.MinParams >= 1){
		; If the function has atleast 1 parameters.
		A_LoopRetVal := A_LoopCond.(v.mode == 3 ? local$ : local$.Value(0))
		} else {
		A_LoopRetVal := A_LoopCond.()
		}
		if (!A_LoopRetVal){
		; If the function returns a non-true value.
		matched := false
		continue
		}
		}
		if (v.clearTrigger){
		;Delete the trigger
		SendInput % "{BS " . StrLen(local$.Value(0)) . "}"
		}
		if (IsLabel(v.label)){
		$ := v.mode == 3 ? local$ : local$.Value(0)
		gosub, % v.label
		} else if (IsFunc(v.label)){
		callbackFunc := Func(v.label)
		if (callbackFunc.MinParams >= 1){
		callbackFunc.(v.mode == 3 ? local$ : local$.Value(0))
		} else {
		callbackFunc.()
		}
		} else {
		toSend := v.label
		;Working out the backreferences
		Loop, % local$.Count()
		StringReplace, toSend,toSend,% "$" . A_Index,% local$.Value(A_index),All
		toSend := RegExReplace(toSend,"([!#\+\^\{\}])","{$1}") ;Escape modifiers
		SendInput,%toSend%
		}
		}
		}
		if (matched){
		typed := ""
		} else if (StrLen(typed) > 350){
		StringTrimLeft,typed,typed,200
		}
		} else {
		if (hotstrings.HasKey(trigger) && label == ""){
		; Removing a hotstring.
		hotstrings.remove(trigger)
		} else {
		; Add to hotstrings object.
		hotstrings[trigger] := {"trigger" : trigger, "label":label, "mode":mode, "clearTrigger" : clearTrigger, "cond": cond}
		}
		}
		return
		__hotstring:
		; This label is triggered every time a key is pressed.
		Hotstring("", "", "CALLBACK")
		return
		}
) ;End of script variable
ExecScript(script,false)
return

;-----Hotkeys-------------------------------------
 
F5::
Send something
return
 
Space::
sendInput ^g{enter 2}
return

ExecScript(Script, Wait:=true)
{
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
    exec.StdIn.Write(script)
    exec.StdIn.Close()
    if Wait
        return exec.StdOut.ReadAll()
}
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Dynamic Hotstrings

06 Jul 2016, 07:25

Thanks, this is so much over my knowledge level that I can't understand anything.

I tried using it like this: (sorry for the amount of ugly code :))

Code: Select all


#include Hotstring.ahk 
#include FileTail.ahk
#SingleInstance, force
#Persistent
#NoEnv
SetBatchLines, -1
SendMode, Input
SetKeyDelay, -1

SetTimer, wincheck, 500

 

    


;#IfWinActive, Telnet EBS6.HUHTAMAKI.COM
;{


script=
(%`
		Menu,Tray,Tip,Hotstrings

;-----Dynamic Hotstrings---------------
; download it from here https://github.com/menixator/ahk-repo/blob/master/Hotstring/Hotstring.ahk

#include Hotstring.ahk 
#include FileTail.ahk


Hotstring("([A-O]{2})(\d)(\d)([012])\s","expand2",3)
Hotstring("(MAX|FRASSE)(\d)(\d)\s","expand1",3)
Hotstring("(\b[A-O])(\d)(\d)([012])\s","expand3",3)
Hotstring("(FRASSE)(\d)(\d)([12])\s","expand4",3)
Hotstring("(\b\d{2,3})\s","expand5",3)
return 




;----Subs for Dynamic hotstrings-------------------

Expand1:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER 3}"
}
else{
Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER}^kBOX{ENTER}" 
}

}
Return

Expand2:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % "^kMAX{ENTER}MAX." $.value(1) "." $.value(2) $.value(3) "." $.value(4)"{ENTER 3}"
}
else{
Send % "^kMAX{ENTER}MAX." $.value(1) "." $.value(2) $.value(3) "." $.value(4)"{ENTER}^kBOX{ENTER}"
sleep 1000
placeholder3 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder3, "\bAvail Qty\s*:(\d+)", Qty)
sleep 100
sendinput %Qty1%{enter}
}
}
Return



Expand3:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % ($.value(4) = 0 ? "^kPLOCK_LOW{ENTER}PLOCK_LOW." : "^kPLOCK{ENTER}PLOCK.") $.value(1) "." $.value(2) $.value(3) "." $.value(4)"{ENTER 3}"
}
else{
Send % ($.value(4) = 0 ? "^kPLOCK_LOW{ENTER}PLOCK_LOW." : "^kPLOCK{ENTER}PLOCK.") $.value(1) "." $.value(2) $.value(3) "." $.value(4)"{ENTER}^kBOX{ENTER}"
sleep 1000
placeholder3 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder3, "\bAvail Qty\s*:(\d+)", Qty)
sleep 100
sendinput %Qty1%{enter}
}
}
Return


Expand4:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % "^kFRASSE{ENTER}FRASSE.PLOCK." $.value(2) $.value(3) "." $.value(4)"{ENTER 3}"
}
else{
Send % "^kFRASSE{ENTER}FRASSE.PLOCK." $.value(2) $.value(3) "." $.value(4)"{ENTER}^kBOX{ENTER}"
sleep 1000
placeholder3 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder3, "\bAvail Qty\s*:(\d+)", Qty)
sleep 100
sendinput %Qty1%{enter}
}
}
Return

Expand5:
placeholder2 = % FileTail("c:\test\test.log", 18)
NewStr := RegExMatch(placeholder2, "\s*Item\s*\>\s*(\d{8})", test)
Temp_art = %test1%
return










Hotstring(trigger, label, mode := 1, clearTrigger := 1, cond := ""){
		global $
		static keysBound := false,hotkeyPrefix := "~$", hotstrings := {}, typed := "", keys := {"symbols": "!""#$%&'()*+,-./:;<=>?@[\]^_``{|}~", "num": "0123456789", "alpha":"abcdefghijklmnopqrstuvwxyz", "other": "BS,Return,Tab,Space", "breakKeys":"Left,Right,Up,Down,Home,End,RButton,LButton,LControl,RControl,LAlt,RAlt,AppsKey,Lwin,Rwin,WheelDown,WheelUp,f1,f2,f3,f4,f5,f6,f7,f8,f9,f6,f7,f9,f10,f11,f12", "numpad":"Numpad0,Numpad1,Numpad2,Numpad3,Numpad4,Numpad5,Numpad6,Numpad7,Numpad8,Numpad9,NumpadDot,NumpadDiv,NumpadMult,NumpadAdd,NumpadSub,NumpadEnter"}, effect := {"Return" : "`n", "Tab":A_Tab, "Space": A_Space, "Enter":"`n", "Dot": ".", "Div":"/", "Mult":"*", "Add":"+", "Sub":"-"}
		if (!keysBound){
		;Binds the keys to watch for triggers.
		for k,v in ["symbols", "num", "alpha"]
		{
		;alphanumeric/symbols
		v := keys[v]
		Loop,Parse, v
		Hotkey,%hotkeyPrefix%%A_LoopField%,__hotstring
		}
		v := keys.alpha
		Loop,Parse, v
		Hotkey, %hotkeyPrefix%+%A_Loopfield%,__hotstring
		for k,v in ["other", "breakKeys", "numpad"]
		{
		;comma separated values
		v := keys[v]
		Loop,Parse, v,`,
		Hotkey,%hotkeyPrefix%%A_LoopField%,__hotstring
		}
		keysBound := true ;keysBound is a static varible. Now, the keys won't be bound twice.
		}
		if (mode == "CALLBACK"){
		; Callback for the hotkey.s
		Hotkey := SubStr(A_ThisHotkey,3)
		if (StrLen(Hotkey) == 2 && Substr(Hotkey,1,1) == "+" && Instr(keys.alpha, Substr(Hotkey, 2,1))){
		Hotkey := Substr(Hotkey,2)
		if (!GetKeyState("Capslock", "T")){
		StringUpper, Hotkey,Hotkey
		}
		}
		shiftState := GetKeyState("Shift", "P")
		uppercase := GetKeyState("Capslock", "T") ? !shiftState : shiftState
		;If capslock is down, shift's function is reversed.(ie pressing shift and a key while capslock is on will provide the lowercase key)
		if (uppercase && Instr(keys.alpha, Hotkey)){
		StringUpper, Hotkey,Hotkey
		}
		if (Instr("," . keys.breakKeys . ",", "," . Hotkey . ",")){
		typed := ""
		return
		} else if Hotkey in Return,Tab,Space
		{
		typed .= effect[Hotkey]
		} else if (Hotkey == "BS"){
		; trim typed var if Backspace was pressed.
		StringTrimRight,typed,typed,1
		return
		} else if (RegExMatch(Hotkey, "Numpad(.+?)", numKey)) {
		if (numkey1 ~= "\d"){
		typed .= numkey1
		} else {
		typed .= effect[numKey1]
		}
		} else {
		typed .= Hotkey
		}
		matched := false
		for k,v in hotstrings
		{
		matchRegex := (v.mode == 1 ? "Oi)" : "") . (v.mode == 3 ? RegExReplace(v.trigger, "\$$", "") : "\Q" . v.trigger . "\E") . "$"
		if (v.mode == 3){
		if (matchRegex ~= "^[^\s\)\(\\]+?\)"){
		matchRegex := "O" . matchRegex
		} else {
		matchRegex := "O)" . matchRegex
		}
		}
		if (RegExMatch(typed, matchRegex, local$)){
		matched := true
		if (v.cond != "" && IsFunc(v.cond)){
		; If hotstring has a condition function.
		A_LoopCond := Func(v.cond)
		if (A_LoopCond.MinParams >= 1){
		; If the function has atleast 1 parameters.
		A_LoopRetVal := A_LoopCond.(v.mode == 3 ? local$ : local$.Value(0))
		} else {
		A_LoopRetVal := A_LoopCond.()
		}
		if (!A_LoopRetVal){
		; If the function returns a non-true value.
		matched := false
		continue
		}
		}
		if (v.clearTrigger){
		;Delete the trigger
		SendInput % "{BS " . StrLen(local$.Value(0)) . "}"
		}
		if (IsLabel(v.label)){
		$ := v.mode == 3 ? local$ : local$.Value(0)
		gosub, % v.label
		} else if (IsFunc(v.label)){
		callbackFunc := Func(v.label)
		if (callbackFunc.MinParams >= 1){
		callbackFunc.(v.mode == 3 ? local$ : local$.Value(0))
		} else {
		callbackFunc.()
		}
		} else {
		toSend := v.label
		;Working out the backreferences
		Loop, % local$.Count()
		StringReplace, toSend,toSend,% "$" . A_Index,% local$.Value(A_index),All
		toSend := RegExReplace(toSend,"([!#\+\^\{\}])","{$1}") ;Escape modifiers
		SendInput,%toSend%
		}
		}
		}
		if (matched){
		typed := ""
		} else if (StrLen(typed) > 350){
		StringTrimLeft,typed,typed,200
		}
		} else {
		if (hotstrings.HasKey(trigger) && label == ""){
		; Removing a hotstring.
		hotstrings.remove(trigger)
		} else {
		; Add to hotstrings object.
		hotstrings[trigger] := {"trigger" : trigger, "label":label, "mode":mode, "clearTrigger" : clearTrigger, "cond": cond}
		}
		}
		return
		__hotstring:
		; This label is triggered every time a key is pressed.
		Hotstring("", "", "CALLBACK")
		return
		}
) ;End of script variable
ExecScript(script,false)
return

;-----Hotstrings---------------------------------


 

 
;----------Locators-----

:c:IN::INLAST{ENTER}INLAST...{ENTER}^kBOX{ENTER}
:c:DIR::DIRECT{ENTER}DIRECT...{ENTER}^kBOX{ENTER}

;----------Articles-----

::GRILL::30183746
::A22061::12221075
::401108::12220834
::401103::10003619
::270000::12220114
::401102::10003621
::2CUP::30184628
::4CUP::30184629
::BAG::30183524
::BAG2::30183713
::BOX::^kBOX{ENTER}
::655104::30140406
::655105::30140162
::711182::10003563
::711195::10003568

;-----Hotkeys-------------------------------------

F5::
Msgbox, YESBOX
return

^Space::
sendInput ^g{enter 2}
return

^Tab:: 
sendinput ^s{enter}
return


^f9::
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

MsgBox, % FileTail("c:\test\test.log", 8)

if(FoundPos != 0){
msgbox, qty detekterat
}
return

^f8::
placeholder = % FileTail("c:\test\test.log", 2)
IfInString, placeholder, Sub Transfer
    MsgBox, Found

else
    MsgBox, Not found
return


^F10::
InputBox, Artnr , Flytta artiklar, Vilken artikel vill du flytta?
InputBox, Antal, Antal, Hur många?
return


^F1::
send {down}%Temp_art%{ENTER}
return

^F4::
send {down}%Artnr%{enter}
sleep 200
send INLAST{enter}INLAST...{enter}
sleep 200
send ^kBOX{enter}%Antal%{enter}
return

!f::

{
placeholder = % FileTail("c:\test\test.log", 2)
IfInString, placeholder, Sub Transfer
{
Sendinput ^n
sleep 100
Sendinput 161
return
}
else
    MsgBox, Not found
return	
}

!h::
Home()
return

^'::
placeholder = % FileTail("c:\test\test.log", 2)
IfInString, placeholder, Inquiry

{
placeholder2 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder2, "\s*Item\s*:\s*(\d{8})", Artikel)
NewStr := RegExMatch(placeholder2, "\bSub\s*:(\w+)", Sub)
NewStr := RegExMatch(placeholder2, "\bLoc\s*:(.*)", Locator)
Home()
sleep 300
sendinput %Artikel1%{enter}
sendinput %Sub1%{enter}%Locator1%{enter 2}
sleep 100
sendinput {Up}^kBOX{enter}
sleep 1500
placeholder3 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder3, "\bAvail Qty\s*:(\d+)", Qty)
sleep 100
sendinput %Qty1%{enter}
return
}
return


;}



;--------------Functions---------------------------------------

Home(){
Sendinput ^n
sleep 100
Sendinput 13131{down}
return
}



ExecScript(Script, Wait:=true)
{
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
    exec.StdIn.Write(script)
    exec.StdIn.Close()
    if Wait
        return exec.StdOut.ReadAll()
}


wincheck:
IfWinActive, ahk_class ConsoleWindowClass
    SetCapsLockState, On
else
    SetCapsLockState, Off
return
The hotkeys work but not the dynamic hotstrings.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Dynamic Hotstrings

06 Jul 2016, 09:06

You're including Hotstring.ahk and using the typed out function I posted. Remove my part (that large part starting with Hotstring(), so there's no duplicate definition. Then you should also see a second AHK icon in the tray.
burton666
Posts: 49
Joined: 09 Dec 2014, 15:26

Re: Dynamic Hotstrings

07 Jul 2016, 00:50

Thanks for all the help, I only got one issue now. I have several parts in the expand: sections witch should enter BOX at sertain parts. But they always print out in lowercase now. Why is that?

Edit: it looks like the Caps Lock key turns of at some random point when printing out the expand section. Sometimes everything is printed in uppercase but most of the times some part of the end is printed in lowercase.

Edit2: I guess it is the set timer part that messes this up, I have been trying using something like:

Code: Select all

#IfWinActive, Telnet EBS6.HUHTAMAKI.COM

{
SetCapsLockState, On
return
}
#IfWinNotActive, Telnet EBS6.HUHTAMAKI.COM
{
SetCapsLockState, Off
return
}
But I can't get that to work either.

Code: Select all

Expand1:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER 3}"
}
else{
Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER}^kBOX{ENTER}" 
}

}
Return

Code: Select all


#include Hotstring.ahk 
#include FileTail.ahk
#SingleInstance, force
#Persistent
#NoEnv
SetBatchLines, -1
SendMode, Input
SetKeyDelay, -1

SetTimer, wincheck, 500

 

    


#IfWinActive, Telnet EBS6.HUHTAMAKI.COM
{


script=
(%`
		Menu,Tray,Tip,Hotstrings

;-----Dynamic Hotstrings---------------
; download it from here https://github.com/menixator/ahk-repo/blob/master/Hotstring/Hotstring.ahk

#include Hotstring.ahk 
#include FileTail.ahk


#IfWinActive, Telnet EBS6.HUHTAMAKI.COM
{
Hotstring("([A-O]{2})(\d)(\d)([012])\s","expand2",3)
Hotstring("(MAX|FRASSE)(\d)(\d)\s","expand1",3)
Hotstring("(\b[A-O])(\d)(\d)([012])\s","expand3",3)
Hotstring("(FRASSE)(\d)(\d)([12])\s","expand4",3)
Hotstring("(\b\d{2,3})\s","expand5",3)
return 
}




;----Subs for Dynamic hotstrings-------------------

Expand1:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER 3}"
}
else{
Send % ($.value(1) = "MAX" ? "^kMAX{ENTER}MAX.PLOCK." : "^kFRASSE{ENTER}FRASSE.PLOCK.") $.value(2) $.value(3) ".{ENTER}^kBOX{ENTER}" 
}

}
Return

Expand2:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % "^kMAX{ENTER}MAX." $.value(1) "." $.value(2) $.value(3) "." $.value(4)"{ENTER 3}"
}
else{
Send % "^kMAX{ENTER}MAX." $.value(1) "." $.value(2) $.value(3) "." $.value(4)"{ENTER}^kBOX{ENTER}"
sleep 1000
placeholder3 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder3, "\bAvail Qty\s*:(\d+)", Qty)
sleep 100
sendinput %Qty1%{enter}
}
}
Return



Expand3:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % ($.value(4) = 0 ? "^kPLOCK_LOW{ENTER}PLOCK_LOW." : "^kPLOCK{ENTER}PLOCK.") $.value(1) "." $.value(2) $.value(3) "." $.value(4)"{ENTER 3}"
}
else{
Send % ($.value(4) = 0 ? "^kPLOCK_LOW{ENTER}PLOCK_LOW." : "^kPLOCK{ENTER}PLOCK.") $.value(1) "." $.value(2) $.value(3) "." $.value(4)"{ENTER}^kBOX{ENTER}"
sleep 1000
placeholder3 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder3, "\bAvail Qty\s*:(\d+)", Qty)
sleep 100
sendinput %Qty1%{enter}
}
}
Return


Expand4:
{
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

if(FoundPos != 0){
Send % "^kFRASSE{ENTER}FRASSE.PLOCK." $.value(2) $.value(3) "." $.value(4)"{ENTER 3}"
}
else{
Send % "^kFRASSE{ENTER}FRASSE.PLOCK." $.value(2) $.value(3) "." $.value(4)"{ENTER}^kBOX{ENTER}"
sleep 1000
placeholder3 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder3, "\bAvail Qty\s*:(\d+)", Qty)
sleep 100
sendinput %Qty1%{enter}
}
}
Return

Expand5:
placeholder2 = % FileTail("c:\test\test.log", 18)
NewStr := RegExMatch(placeholder2, "\s*Item\s*\>\s*(\d{8})", test)
Temp_art = %test1%
return



wincheck:
IfWinActive, ahk_class ConsoleWindowClass
    SetCapsLockState, On
else
    SetCapsLockState, Off
return

) ;End of script variable
ExecScript(script,false)
return

;-----Hotstrings---------------------------------


 

 
;----------Locators-----

:c:IN::INLAST{ENTER}INLAST...{ENTER}^kBOX{ENTER}
:c:DIR::DIRECT{ENTER}DIRECT...{ENTER}^kBOX{ENTER}

;----------Articles-----

::GRILL::30183746
::A22061::12221075
::401108::12220834
::401103::10003619
::270000::12220114
::401102::10003621
::2CUP::30184628
::4CUP::30184629
::BAG::30183524
::BAG2::30183713
::BOX::^kBOX{ENTER}
::655104::30140406
::655105::30140162
::711182::10003563
::711195::10003568

;-----Hotkeys-------------------------------------

F5::
Msgbox, YESBOX
return

^Space::
sendInput ^g{enter 2}
return

^Tab:: 
sendinput ^s{enter}
return


^f9::
placeholder2 = % FileTail("c:\test\test.log", 8)
FoundPos := RegExMatch(placeholder2, "^\bQty\s*:\s*\d+")

MsgBox, % FileTail("c:\test\test.log", 8)

if(FoundPos != 0){
msgbox, qty detekterat
}
return

^f8::
placeholder = % FileTail("c:\test\test.log", 2)
IfInString, placeholder, Sub Transfer
    MsgBox, Found

else
    MsgBox, Not found
return


^F10::
InputBox, Artnr , Flytta artiklar, Vilken artikel vill du flytta?
InputBox, Antal, Antal, Hur många?
return


^F1::
send {down}%Temp_art%{ENTER}
return

^F4::
send {down}%Artnr%{enter}
sleep 200
send INLAST{enter}INLAST...{enter}
sleep 200
send ^kBOX{enter}%Antal%{enter}
return

!f::

{
placeholder = % FileTail("c:\test\test.log", 2)
IfInString, placeholder, Sub Transfer
{
Sendinput ^n
sleep 100
Sendinput 161
return
}
else
    MsgBox, Not found
return	
}

!h::
Home()
return

^'::
placeholder = % FileTail("c:\test\test.log", 2)
IfInString, placeholder, Inquiry

{
placeholder2 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder2, "\s*Item\s*:\s*(\d{8})", Artikel)
NewStr := RegExMatch(placeholder2, "\bSub\s*:(\w+)", Sub)
NewStr := RegExMatch(placeholder2, "\bLoc\s*:(.*)", Locator)
Home()
sleep 300
sendinput %Artikel1%{enter}
sendinput %Sub1%{enter}%Locator1%{enter 2}
sleep 100
sendinput {Up}^kBOX{enter}
sleep 1500
placeholder3 = % FileTail("c:\test\test.log", 14)
NewStr := RegExMatch(placeholder3, "\bAvail Qty\s*:(\d+)", Qty)
sleep 100
sendinput %Qty1%{enter}
return
}
return


}



;--------------Functions---------------------------------------

Home(){
Sendinput ^n
sleep 100
Sendinput 13131{down}
return
}



ExecScript(Script, Wait:=true)
{
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
    exec.StdIn.Write(script)
    exec.StdIn.Close()
    if Wait
        return exec.StdOut.ReadAll()
}


wincheck:
IfWinActive, ahk_class ConsoleWindowClass
    SetCapsLockState, On
else
    SetCapsLockState, Off
return
User avatar
majkinetor
Posts: 10
Joined: 29 Nov 2013, 07:56

Re: Dynamic Hotstrings

28 Jul 2016, 13:42

This library is awesome. Thanks for it.

Could I use this to achieve the following:

- All words are hotstrings (I know I can do this by specifying a regex to match a word)
- I send the word to the service and if I get the response, I replace it with it, otherwise, nothing is done.

For example I write words on english and send it to the translator service (which is local so its fast), so when I get the corresponding word I replace it with it, otherwise I ignore it. This is not what I am trying to do but lets go with it for the sake of example.
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Dynamic Hotstrings

28 Jul 2016, 13:48

majkinetor is back!!!!!!!!!!!
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Dynamic Hotstrings

02 Sep 2016, 09:26

First, nice script!
If I get what you're asking, you want to, eg, bind the d key to some action and still let it be part of a hotstring. If so, you could make a function that always returns false, and let it be the #If condiotion for the d hotkey like this:

Code: Select all

#If alwaysFalse()
d::return
#If
alwaysFalse()
{
	; Some action you want the d key to perform
	return 0
}
Then, when you hit d the alwaysFalse() function will be evaluated but since it returns false, the other d hotkey will be used instead, i.e., the one from the Hotstrings()-function. I haven't used this script before, but it looks like you just need to change

Code: Select all

	;  [...]
	if (mode == "CALLBACK"){
	   ; Callback for the hotkey.s
		Hotkey := SubStr(A_ThisHotkey,3)
	; [...]
to

Code: Select all

	;  [...]
	if (mode == "CALLBACK"){
		; Callback for the hotkey.s
		if strlen(A_ThisHotkey)=1
			Hotkey := A_ThisHotkey
		else
			Hotkey := SubStr(A_ThisHotkey,3)
	; [...]
or, add ~$ to the new hotkey, like ~$d::return.
Tested only with the example hotstring in this thread, i.e., dont -> don't etc.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Dynamic Hotstrings

02 Sep 2016, 20:00

hoppfrosch wrote:majkinetor is back!!!!!!!!!!!
whattttttttttttttt

Guest

Re: Dynamic Hotstrings

22 Nov 2016, 03:54

I have one Problem regarding the $ Operator in Hotkey Definition, that's really driving me mad.
I'm using the "Dynamic Hotstring" Script.

Parallel I'm using an "Autocomplete" Function in the same Program. (Originally created by Uberi and Thodan)

page-14
Autocomplete

Both Functions hook an Hotkey on every keyboard-key-press.
No Problem so far. But the "Autocomplete" Function only works when the Modifier is a simple ~, like below.

Code: Select all

Loop, Parse, NormalKeyList, `n
Hotkey, ~%c%, __hs
... and the "Dynamic Hotstring" Function only works when the $ Modifier is added, like below.

Code: Select all

Hotkey, ~$%c%, __hs
((COMMENT: In the original "Dynamic Hotstring"-Code it's:
Hotkey, %m%%c%, __hs
where m is the Prefix ~$ I only wrote it out so the problem could be seen easier.

As far as I understood the manual, the sense of the $-Operator is only to avoid, that the Hotkey is fired, when in the called function a Send-Command sends exactly the Hotkey. Consequently the function should also work without the $-Sign. Especially if the case of identical Send-Text and Hotkey-Name isn't true.

I'm trying around for days now, but couldn't find out why the Dynamic-Hotstring-Function only works with added $-Sign and the Autocomplete Function doesn't work with the $-Sing.

Any Help is appreciated!
User avatar
Artist
Posts: 1
Joined: 05 Oct 2016, 03:02

Re: Dynamic Hotstrings

22 Nov 2016, 03:59

I have one Problem regarding the $ Operator in Hotkey Definition, that's really driving me mad.
I'm using the "Dynamic Hotstring" Script.

Parallel I'm using an "Autocomplete" Function in the same Program. (Originally created by Uberi and Thodan)

https://autohotkey.com/board/topic/6099 ... 12/page-14
https://github.com/thdoan/Autocomplete

Both Functions hook an Hotkey on every keyboard-key-press.
No Problem so far. But the "Autocomplete" Function only works when the Modifier is a simple ~, like below.

Code: Select all

Loop, Parse, NormalKeyList, `n
Hotkey, ~%c%, __hs
... and the "Dynamic Hotstring" Function only works when the $ Modifier is added, like below.

Code: Select all

Hotkey, ~$%c%, __hs
((COMMENT: In the original "Dynamic Hotstring"-Code it's:

Code: Select all

Hotkey, %m%%c%, __hs
where m is the Prefix ~$ I only wrote it out so the problem could be seen easier.

As far as I understood the manual, the sense of the $-Operator is only to avoid, that the Hotkey is fired, when in the called function a Send-Command sends exactly the Hotkey. Consequently the function should also work without the $-Sign. Especially if the case of identical Send-Text and Hotkey-Name isn't true.

I'm trying around for days now, but couldn't find out why the Dynamic-Hotstring-Function only works with added $-Sign and the Autocomplete Function doesn't work with the $-Sing.

Any Help is appreciated!

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: hiahkforum and 156 guests