thqby's AutoHotkey_H v2.0 & v2.1
thqby's AutoHotkey_H v2.0 & v2.1
thqby's AutoHotkey_H started as a fork of AutoHotkey_L v2, merging the branch HotKeyIt/ahkdll-v2, but with some changes.
See the README of each branch for details.
See the README of each branch for details.
- Attachments
-
- Ahk2Exe.zip
- (468.07 KiB) Downloaded 230 times
Last edited by thqby on 28 Mar 2024, 21:31, edited 1 time in total.
Re: thqby's AutoHotkey_H v2.0 & v2.1
Any chance of merging v1 as well? Thanks.
Re: thqby's AutoHotkey_H v2.0 & v2.1
No interest in merging v1, debugging v1 scripts is maddening.
-
- Posts: 6
- Joined: 12 May 2024, 19:52
- Contact:
Re: thqby's AutoHotkey_H v2.0 & v2.1
I am an AutoHotkey beginner and wanted to use multi-threading, so I installed the exe and dll files you provided. I can use the NewThread function, but I get an error when using other functions like ahkPause, with the message "Error: This value of type 'Integer' has no method named 'ahkPause'." I have tried versions 2.0.12 and 2.0.14, both of which gave me errors, but it runs fine with the official download of v2.0-beta.1. Did I miss any installation steps? Below is the code I found in the official documentation and tried to run.
[Mod edit: Fixed the codebox tags. They go around the code, not both tags before the code.]
Code: Select all
#Requires AutoHotkey v2.0.12
#SingleInstance Force
dllpath:=A_AhkDir "\AutoHotkey.dll"
dll:=NewThread("
(
Persistent
Loop
ToolTip A_TickCount
)",,dllpath)
Sleep 1000
dll.ahkPause("On")
[Mod edit: Fixed the codebox tags. They go around the code, not both tags before the code.]
Re: thqby's AutoHotkey_H v2.0 & v2.1
Maybe you used to use ahk-wrapped function NewThread. I didn't package these into ahk. You can still use these features through functions like ahkPause(1, NewThread(...)).
You can see the changes in the readme of the github repository.
You can see the changes in the readme of the github repository.
-
- Posts: 6
- Joined: 12 May 2024, 19:52
- Contact:
Re: thqby's AutoHotkey_H v2.0 & v2.1
Thank you very much for your guidance. I've learned how to use ahkPause, but I have encountered another issue regarding terminating a thread.
I found that Thread("Terminate", false, dll) does not work, while ahkPause does work. I would like to know how to properly terminate a thread. I apologize for bothering you with such a simple question, but I have been struggling for an hour and still can't figure it out. Thank you again for your help.
Here is my code:
[Mod edit: Again, fixed the codebox tags. They go around the code, not both tags before the code.]
I found that Thread("Terminate", false, dll) does not work, while ahkPause does work. I would like to know how to properly terminate a thread. I apologize for bothering you with such a simple question, but I have been struggling for an hour and still can't figure it out. Thank you again for your help.
Here is my code:
Code: Select all
#Requires AutoHotkey v2.1-alpha.10
#SingleInstance Force
; Create a new thread and save its thread ID
dll := NewThread("
(
Loop {
ToolTip 'Thread running'
Sleep 1000
}
)")
Sleep 2000
; Attempt to terminate the newly created thread
Thread("Terminate", false, dll)
Sleep 2000
MsgBox "End"
[Mod edit: Again, fixed the codebox tags. They go around the code, not both tags before the code.]
Re: thqby's AutoHotkey_H v2.0 & v2.1
@changxiaotiao — Twice now we have fixed your codebox tags. The code goes in between the pair of tags, not after them. Please place the tags correctly when you post code. You can also use [code][/code] tags, which default to AHK syntax highlighting. They also go around the code, and there is an icon for their use above the reply area.
-
- Posts: 6
- Joined: 12 May 2024, 19:52
- Contact:
Re: thqby's AutoHotkey_H v2.0 & v2.1
I'm sorry for the mistakes I made in formatting the code. Thank you so much for fixing them.boiler wrote: ↑13 May 2024, 22:39@changxiaotiao — Twice now we have fixed your codebox tags. The code goes in between the pair of tags, not after them. Please place the tags correctly when you post code. You can also use [code][/code] tags, which default to AHK syntax highlighting. They also go around the code, and there is an icon for their use above the reply area.
Re: thqby's AutoHotkey_H v2.0 & v2.1
idk if you can use normal newthread object but i found this
source := https://github.com/thqby/AutoHotkey_H/issues/74
Code: Select all
myvar := 50
Script := "
(
MsgBox Worker(A_MainThreadID)['myvar']
)"
Worker(Script)
MsgBox "end"
-
- Posts: 6
- Joined: 12 May 2024, 19:52
- Contact:
Re: thqby's AutoHotkey_H v2.0 & v2.1
@xMaxrayx
Sorry, I don't know how to reply to your private message. I can now use multithreading, but I'm having an issue with the terminate function. For now, I've used ahkPause as a substitute, and the script runs fine.
Sorry, I don't know how to reply to your private message. I can now use multithreading, but I'm having an issue with the terminate function. For now, I've used ahkPause as a substitute, and the script runs fine.
Re: thqby's AutoHotkey_H v2.0 & v2.1
While still in the “new member” status, you will not be able to send private messages.changxiaotiao wrote: ↑ Sorry, I don't know how to reply to your private message.
Re: thqby's AutoHotkey_H v2.0 & v2.1
I see many thanks, im not good with AHK-H but I found "ExitApp" method with class workerchangxiaotiao wrote: ↑15 May 2024, 02:02@xMaxrayx
Sorry, I don't know how to reply to your private message. I can now use multithreading, but I'm having an issue with the terminate function. For now, I've used ahkPause as a substitute, and the script runs fine.
Code: Select all
class Worker {
/**
* Enumerates ahk threads.
* @return An enumerator which will return items contained threadid and workerobj.
* Terminate the thread asynchronously.
*/
ExitApp() => void
Re: thqby's AutoHotkey_H v2.0 & v2.1
Ok I found something weird if the thread closed it will close the Msgbox but not with tooltip. maybe it's a bug
Code: Select all
script:= ("
(
MsgBox 'hello from another thread'
i := 1
while i != 0 {
ToolTip '<3'
}
)")
; Worker(0,script,"sss")
L := worker(script,,"ss" )
Sleep(500)
L.ExitApp() ; it close the 'hello from another thread' but not the tool top
MsgBox "hello from main script"
Re: thqby's AutoHotkey_H v2.0 & v2.1
Ok i found it close the msgbox but not with loop and soundplay
Code: Select all
script:= ("
(
MsgBox "lol"
SoundPlay("C:\Users\Max_Laptop\Documents\Audacity\waiting for a window.wav" , 1)
OnExit ExitFunc
ExitFunc(*){
MsgBox 'good bey'
}
)")
; Worker(0,script,"sss")
L := worker(script,,"pizaa" )
Sleep(500)
L.ExitApp() ;it closes msgbox
MsgBox "hello from main script"
Re: thqby's AutoHotkey_H v2.0 & v2.1
can you tell me how did use ahkpause?
according to this doc
https://hotkeyit.github.io/v1/docs/commands/ahkPause.htm
my code (i added 64dll)
I cant use ahkpause with DLL object
according to this doc
https://hotkeyit.github.io/v1/docs/commands/ahkPause.htm
my code (i added 64dll)
Code: Select all
dllpath:=A_AhkDir "\AutoHotkey64.dll"
DllCall("LoadLibrary","Str",dllpath) ; Load the AutoHotkey module.
ThreadID:=DllCall(dllpath "\NewThread","Str","
(
Persistent
Loop
ToolTip A_TickCount
)","Str","","Str","","CDecl") ; start a new thread, just the function.
Sleep 1000
DllCall(dllpath "\ahkPause","Str","On","Uint",ThreadID,"CDecl") ; Pause thread.
MsgBox "End"
dll:=NewThread("
(
Persistent
Loop
ToolTip A_TickCount
)",,dllpath)
Sleep 1000
dll.ahkPause("On")
MsgBox "End"
Code: Select all
Error: This value of type "Integer" has no method named "ahkPause".
073: dll := NewThread("Persistent
Loop
ToolTip A_TickCount",,dllpath)
079: Sleep(1000)
▶ 080: dll.ahkPause("On")
081: MsgBox("End")
082: Exit
-
- Posts: 6
- Joined: 12 May 2024, 19:52
- Contact:
Re: thqby's AutoHotkey_H v2.0 & v2.1
@xMaxrayx
Yes, I also found that ToolTip cannot be closed this way. Can you try this code ?
I saw the author on GitHub mentioned that it's possible to forcibly break the loop, but I tested it and it didn't work. MsgBox also couldn't break the loop.
It might be a version issue. The usage of ahkPause has changed. You can try
You can see the explanation at this link.https://github.com/thqby/AutoHotkey_H
Yes, I also found that ToolTip cannot be closed this way. Can you try this code ?
Code: Select all
dll["Thread"]("Terminate", true)
It might be a version issue. The usage of ahkPause has changed. You can try
Code: Select all
ahkPause(1, dll).
Re: thqby's AutoHotkey_H v2.0 & v2.1
I found this error maybe interesting
code :
error :
soundplay still running after dll1.ExitApp() but dll1.Reload() can't be work ,
so what's the thread who do the soundplay? is the thread was real?
i did this code and I got this
I tried relauding dll1 without using exitapp() and turn out the audio running twice.
code :
Code: Select all
string1:="
(
SoundPlay("C:\Users\Max_Laptop\Documents\Audacity\waiting for a window.wav",1)
)"
dll1:= Worker(string1 )
Sleep(1)
dll1.ExitApp()
Sleep(500)
dll1.Reload()
dll1:=Worker(string1)
Code: Select all
Error: (0x80010012) The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call did not execute.
081: dll1.ExitApp()
082: Sleep(500)
▶ 083: dll1.Reload()
084: dll1 := Worker(string1)
085: Exit
soundplay still running after dll1.ExitApp() but dll1.Reload() can't be work ,
so what's the thread who do the soundplay? is the thread was real?
i did this code and I got this
Code: Select all
MsgBox A_MainThreadID "`n" dll1.ThreadID
Code: Select all
string1:="
(
SoundPlay("C:\Users\Max_Laptop\Documents\Audacity\waiting for a window.wav",1)
)"
dll1:= Worker(string1, ,"pizaa")
Sleep(1)
; dll1.ExitApp()
Sleep(500)
MsgBox A_MainThreadID "`n" dll1.ThreadID
dll1.Reload()
Re: thqby's AutoHotkey_H v2.0 & v2.1
yeah sadly i tried it again and didn't work the weird part tooltip can't be work with "worker" class unlike with "NewThread" classchangxiaotiao wrote: ↑15 May 2024, 11:27@xMaxrayx
Yes, I also found that ToolTip cannot be closed this way. Can you try this code ?I saw the author on GitHub mentioned that it's possible to forcibly break the loop, but I tested it and it didn't work. MsgBox also couldn't break the loop.Code: Select all
dll["Thread"]("Terminate", true)
It might be a version issue. The usage of ahkPause has changed. You can tryYou can see the explanation at this link.https://github.com/thqby/AutoHotkey_HCode: Select all
ahkPause(1, dll).
thanks I managed to pause the thread with ahkPause but it doesn't work for soundplay , it plays the whole music length then pause, it's like ahkPause pause between two process but not while the current process still running and not finished.
Code: Select all
f::{
Critical
ahkPause(1, dll)
ToolTip "yes"
}
;/####
/*
dll := Worker(script)
script := ("
(
Loop {
; SoundPlay("C:\Users\Max_Laptop\Documents\Audacity\waiting for a window.wav",0)
ToolTip 'Thread running'
Sleep(1000)
}
)")
*/
dll:= NewThread("
(
Loop {
SoundPlay("C:\Users\Max_Laptop\Documents\Audacity\waiting for a window.wav")
; ToolTip 'Thread running'
Sleep 200
}
)")
; dll["thread"]("Terminate", true)
; Critical
; Thread("Interrupt", dll)
; ahkPause(1, dll.ThreadID)
; dll.ExitApp()
Sleep 500
; ahkPause(1, dll)
MsgBox 'end'
-
- Posts: 6
- Joined: 12 May 2024, 19:52
- Contact:
Re: thqby's AutoHotkey_H v2.0 & v2.1
I have tested and come to the same conclusions as you:
1: pause will only take effect after the current thread finishes.
2: dll.Reload() can work twice.
3: If ExitApp is called first, followed by Reload, an error will occur.
However, I found that ExitApp can stop the sound playback
The external Sleep determines the entire thread's duration, while the internal Sleep determines how long the current loop runs, but it will never exceed the total thread duration.
and the second parameter of SoundPlay must be 0
1: pause will only take effect after the current thread finishes.
2: dll.Reload() can work twice.
3: If ExitApp is called first, followed by Reload, an error will occur.
However, I found that ExitApp can stop the sound playback
Code: Select all
dll:=Worker("
(
loop{
soundplay("c:\Program Files\AutoHotkey\Media\test2.wav",0)
sleep 5000
;msgbox "runing"
}
)")
Sleep 10000
dll.ExitApp()
;dll.Reload()
Persistent
and the second parameter of SoundPlay must be 0
Re: thqby's AutoHotkey_H v2.0 & v2.1
worker_obj.ExitApp() cannot be used to exit a thread in a loop.
Forcing thread exit will result in a large amount of resources not being released properly.
worker_obj['Thread']('Terminate', true) can interrupt the loop, but it may also prevent the release of some resources.
Forcing thread exit will result in a large amount of resources not being released properly.
worker_obj['Thread']('Terminate', true) can interrupt the loop, but it may also prevent the release of some resources.
Who is online
Users browsing this forum: No registered users and 9 guests