NOOB guide on how to use H ? Topic is solved
- Kintaro-OEx
- Posts: 13
- Joined: 17 Apr 2018, 15:48
NOOB guide on how to use H ?
Hello together!
I am really running into a wall to start using version H. Simply because it is not a normal installation like the normal version of AHK.
My main goal is to proceed using multiple THREADS and not timer which are still single threaded and infinite loops do not work then obviously.
I truly struggle to find any helpful stuff with Google.
Would love you so much for some guidance!!!!
cheers
I am really running into a wall to start using version H. Simply because it is not a normal installation like the normal version of AHK.
My main goal is to proceed using multiple THREADS and not timer which are still single threaded and infinite loops do not work then obviously.
I truly struggle to find any helpful stuff with Google.
Would love you so much for some guidance!!!!
cheers
Re: NOOB guide on how to use H ? Topic is solved
All you need is the AutoHotkey.exe, simply replace yours (backup your current one!).
If you don't know which one to use, start with the one that does not require vc runtime: 32-bit MT or 64-bit MT.
From there all you need for multi-threading is AhkThread function:
Read in v1 or v2 docs about the methods you can use with threads, like ahkgetvar, ahkFunction, ahkassign and so on.
Further you should use CriticalObject to share data between threads:
If you don't know which one to use, start with the one that does not require vc runtime: 32-bit MT or 64-bit MT.
From there all you need for multi-threading is AhkThread function:
Code: Select all
ahk1:=AhkThread("MsgBox thread 1")
ahk2:=AhkThread("MsgBox thread 2")
MsgBox main thread
Further you should use CriticalObject to share data between threads:
Code: Select all
obj := CriticalObject() ; Create new critical object
Loop 4 ; Create 4 Threads.
AhkThread%A_Index% := AhkThread("obj:=CriticalObject(" (&obj) ")`nLoop`nobj[" A_Index "]:= A_Index")
Loop ; Show current content of object.
ToolTip % obj.1 "`n" obj.2 "`n" obj.3 "`n" obj.4
Esc::ExitApp
- Kintaro-OEx
- Posts: 13
- Joined: 17 Apr 2018, 15:48
Re: NOOB guide on how to use H ?
Cheers mate! I also got the compiler working properly.HotKeyIt wrote: ↑19 Nov 2020, 19:42All you need is the AutoHotkey.exe, simply replace yours (backup your current one!).
If you don't know which one to use, start with the one that does not require vc runtime: 32-bit MT or 64-bit MT.
From there all you need for multi-threading is AhkThread function:Read in v2 docs about the methods you can use with threads, like ahkgetvar, ahkFunction, ahkassign and so on.Code: Select all
ahk1:=AhkThread("MsgBox thread 1") ahk2:=AhkThread("MsgBox thread 2") MsgBox main thread
Further you should use CriticalObject to share data between threads:Code: Select all
obj := CriticalObject() ; Create new critical object Loop 4 ; Create 4 Threads. AhkThread%A_Index% := AhkThread("obj:=CriticalObject(" (&obj) ")`nLoop`nobj[" A_Index "]:= A_Index") Loop ; Show current content of object. ToolTip % obj.1 "`n" obj.2 "`n" obj.3 "`n" obj.4 Esc::ExitApp
Can you give me a Headstarter with a simple script with 2 THREADS. THREAD_A does press "a" constantly and THREAD_B "b" for the matter.
From there I am sure that I can move on "easily".
In any case. Thank you very much!
EDIT 00:
I got the following working but I honestly do not know how "exactly" it works with the "function call".
Am I able to separate the function definition from the "call" in AhkThread ?
Code: Select all
__THREAD_A := AhkThread("
(
Loop
{
SendInput {a}
sleep 750
}
)", "")
__THREAD_B := AhkThread("
(
Loop
{
SendInput {b}
sleep 500
}
)", "")
Re: NOOB guide on how to use H ?
Don't forget #Persistent for your main thread, otherwise it will exit the program.
Yes you are able to separate them but it affects performance and you need a reference to be able to call it
Yes you are able to separate them but it affects performance and you need a reference to be able to call it
Code: Select all
#Persistent
__THREAD_A := AhkThread("
(
#Persistent
fun(a){
MsgBox `% ""From Thread:``n"" a
}
)")
__THREAD_B := AhkThread("
(
exe:=AhkExported()
__THREAD_A := Object(" (&__THREAD_A) ")
exe.ahkFunction(""fun"",""Hello World!"")
__THREAD_A.ahkFunction(""fun"",""Hello World!"")
)")
fun(a){
MsgBox % "From Main:`n" a
}
- Kintaro-OEx
- Posts: 13
- Joined: 17 Apr 2018, 15:48
Re: NOOB guide on how to use H ?
HotKeyIt wrote: ↑20 Nov 2020, 03:19Don't forget #Persistent for your main thread, otherwise it will exit the program.
Yes you are able to separate them but it affects performance and you need a reference to be able to call itCode: Select all
#Persistent __THREAD_A := AhkThread(" ( #Persistent fun(a){ MsgBox `% ""From Thread:``n"" a } )") __THREAD_B := AhkThread(" ( exe:=AhkExported() __THREAD_A := Object(" (&__THREAD_A) ") exe.ahkFunction(""fun"",""Hello World!"") __THREAD_A.ahkFunction(""fun"",""Hello World!"") )") fun(a){ MsgBox % "From Main:`n" a }
Oh man you are great .
You "accidently" answered my follow-up question/issue.
With the following part I am getting the last 20 lines of a logfile/textfile. The same example is working fine outside of AhkThread.
While using it with AhkThread it obviously shows me "The following variable name contains an illegal character": namely ' " ' .
Code: Select all
USUAL AHK SCRIPT:
Last20Lines := InStr(FileContents, "`n" , false, -1, 20)
Code: Select all
AhkThread SCRIPT:
Last20Lines := InStr(FileContents, ""``n"" , false, -1, 20)
Why double " `` " . I do understand the double " " " part, for example ""simple text"" would work in a regular expression.
cheers mate!
Re: NOOB guide on how to use H ?
See difference:
So if you use MsgBox % "a`nb" you will have not valid code!
Code: Select all
MsgBox % "a`nb"
MsgBox % "a``nb"
Code: Select all
MsgBox "a
b"
Re: NOOB guide on how to use H ?
HotKeyIt, I think a bit of confusion is caused by information being in the AutoHotkey_H v2.chm, when many users are using AutoHotkey_H v1 and coming from AutoHotkey_L v1. In addition, AutoHotkey_L v2 is still an experimental alpha (from which AutoHotkey_H v2 is merged with), so subject to more script breaking changes.
If AutoHotkey_H v2.chm is to be used as an unified help file for both v1 and v2, then perhaps this should be more clearly clarified, so that v1 users will be less confused.
Re: NOOB guide on how to use H ?
I see.
I will take a look and either create a v1 chm or make a unified version so it can be used for both and will have examples for both, v1 and v2.
I will take a look and either create a v1 chm or make a unified version so it can be used for both and will have examples for both, v1 and v2.
Re: NOOB guide on how to use H ?
Either way would be nice. It would be good to have clarification as to which extra features belong to which version of AHK_H.
Re: NOOB guide on how to use H ?
Thanks to the information here, I finally managed to get an idea of how things work. Actually it was very simple. But it's a little hard to understand.
Thank you.
Thank you.
Re: NOOB guide on how to use H ?
I have added v1 docs, also available online: https://hotkeyit.github.io/v1/docs/AutoHotkey.htm
Re: NOOB guide on how to use H ?
What should I do to kill a thread.
When a Thread is killed, is all the ram it uses back? Or will the leaks remain in the ram as long as the main process survives?
Some operations inevitably lead to leaks. The ram cannot be recovered unless the process is terminated. Is it possible to do this with threads?
I'm sorry to change the subject. But I didn't want to make it crowded with an extra subject.
When a Thread is killed, is all the ram it uses back? Or will the leaks remain in the ram as long as the main process survives?
Some operations inevitably lead to leaks. The ram cannot be recovered unless the process is terminated. Is it possible to do this with threads?
I'm sorry to change the subject. But I didn't want to make it crowded with an extra subject.
Re: NOOB guide on how to use H ?
If you end thread properly (see ahkTerminate), there will be no leaks, however if you kill thread without letting it free resources, e.g. dll.ahkTerminate(-1), it will lead to leaks.
Re: NOOB guide on how to use H ?
Looks good, and thank you for the update.HotKeyIt wrote: ↑24 Jan 2021, 06:50I have added v1 docs, also available online: https://hotkeyit.github.io/v1/docs/AutoHotkey.htm
Re: NOOB guide on how to use H ?
anyone have backup of v2 version?
edit : ok i found it
edit : ok i found it