AHK_H v2 beta

Ask for help, how to use AHK_H, etc.
robodesign
Posts: 941
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

AHK_H v2 beta

Post by robodesign » 31 Jul 2021, 18:18

Hello!

I'm wondering when will the next version of AHK_H v2 be available... Is it planned?

Thank you.

I'm eager to migrate to v2.

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

User avatar
thqby
Posts: 560
Joined: 16 Apr 2021, 11:18
Contact:

Re: AHK_H v2 beta

Post by thqby » 31 Jul 2021, 19:30

This is my AHK_H V2 Beta.1 (https://github.com/thqby/autohotkey_h), but there is a little change with Hotkeyit's AHK_H.

HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: AHK_H v2 beta

Post by HotKeyIt » 31 Jul 2021, 19:54

It will be available soon, I need to decide and adapt a few features.

User avatar
DuyMinh
Posts: 40
Joined: 05 May 2017, 08:34

Re: AHK_H v2 beta

Post by DuyMinh » 09 Aug 2021, 04:52

thqby wrote:
31 Jul 2021, 19:30
This is my AHK_H V2 Beta.1 (https://github.com/thqby/autohotkey_h), but there is a little change with Hotkeyit's AHK_H.
I cannot using ExeThread or ThreadObj in this fork, only thread function NewThread can be use, but this func is very useless, only run child thread and dont have some method for thread manager like exethread or threadobj. Can you fix it?

arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: AHK_H v2 beta

Post by arcticir » 09 Aug 2021, 06:19

@DuyMinh

exethread is a simple wrapper for NewThread. You can try to modify it.

Code: Select all

exethread(s:="",p:="",t:="",w:=0){
  static lib
  if !lib
    lib:=GetModuleHandle(),ahkFunction:=GetProcAddress(lib,"ahkFunction"),ahkPostFunction:=GetProcAddress(lib,"ahkPostFunction"),addFile:=GetProcAddress(lib,"addFile"),addScript:=GetProcAddress(lib,"addScript")
        ,ahkExec:=GetProcAddress(lib,"ahkExec"),ahkExecuteLine:=GetProcAddress(lib,"ahkExecuteLine"),ahkFindFunc:=GetProcAddress(lib,"ahkFindFunc"),ahkFindLabel:=GetProcAddress(lib,"ahkFindLabel")
        ,ahkgetvar:=GetProcAddress(lib,"ahkgetvar"),ahkassign:=GetProcAddress(lib,"ahkassign"),ahkLabel:=GetProcAddress(lib,"ahkLabel"),ahkPause:=GetProcAddress(lib,"ahkPause")
		,ahkIsUnicode:=GetProcAddress(lib,"ahkIsUnicode"),ahkReady:=GetProcAddress(lib,"ahkReady")
	thread:={(""):ThreadID:=s=""?GetCurrentThreadId():NewThread((w?"SetEvent(" hEvent:=CreateEvent() ")`n":"") s,p,t)
	  ,_ahkFunction:DynaCall(ahkFunction,"s==sttttttttttui","",0,0,0,0,0,0,0,0,0,0,ThreadID)
	  ,_ahkPostFunction:DynaCall(ahkPostFunction,"i==sttttttttttui","",0,0,0,0,0,0,0,0,0,0,ThreadID)
	  ,ahkFunction:DynaCall(ahkFunction,"s==sssssssssssui","","","","","","","","","","","",ThreadID)
	  ,ahkPostFunction:DynaCall(ahkPostFunction,"i==sssssssssssui","","","","","","","","","","","",ThreadID)
	  ,addFile:DynaCall(addFile,"ut==siui","",0,ThreadID)
	  ,addScript:DynaCall(addScript,"ut==siui","",0,ThreadID)
	  ,ahkExec:DynaCall(ahkExec,"ut==sui","",ThreadID)
	  ,ahkExecuteLine:DynaCall(ahkExecuteLine,"ut==utuiuiui",0,0,0,ThreadID)
	  ,ahkFindFunc:DynaCall(ahkFindFunc,"ut==sui","",ThreadID)
	  ,ahkFindLabel:DynaCall(ahkFindLabel,"ut==sui","",ThreadID)
	  ,ahkgetvar:DynaCall(ahkgetvar,"s==suiui","",0,ThreadID)
	  ,ahkassign:DynaCall(ahkassign,"i==ssui","","",ThreadID)
	  ,ahkLabel:DynaCall(ahkLabel,"ui==suiui","",0,ThreadID)
	  ,ahkPause:DynaCall(ahkPause,"ui==sui","",ThreadID)
	  ,ahkIsUnicode:DynaCall(ahkIsUnicode,"ui==")
	  ,ahkReady:DynaCall(ahkReady,"ui==ui",ThreadID)}
	thread.ahkterminate:=Func("Exethread_exit").Bind(ThreadID)
	if w
		WaitForSingleObject(hEvent,w),CloseHandle(hEvent)
	return thread
}
Exethread_exit(ThreadID){
	static pExitApp:=NumGet(GetProcAddress(0,"g_ThreadExitApp"),"PTR"),Exethread_CloseWindows:=CallbackCreate("Exethread_CloseWindows")
	if hThread:=OpenThread(THREAD_ALL_ACCESS:=2032639,true,ThreadID)
		success:=QueueUserAPC(pExitApp,hThread,0),CloseHandle(hThread),PostThreadMessage(ThreadID, 0, 0, 0),EnumThreadWindows(ThreadID,Exethread_CloseWindows,0)
	return success
}
Exethread_CloseWindows(hwnd,value){
	If (WinGetClass("ahk_id " hwnd)!="AutoHotkey")
		SendMessage_(hwnd,16,0,0) ;WM_CLOSE:=16
	return true
}
But I don't recommend old H users to use thqby's version, he forced L2-H2 merge with L2 as the main one, which causes some H functions not to work properly, and it seems that thqby has no intention to fix these problems.

User avatar
thqby
Posts: 560
Joined: 16 Apr 2021, 11:18
Contact:

Re: AHK_H v2 beta

Post by thqby » 09 Aug 2021, 11:55

Most of the missing functions are implemented by AHK and can #include library files.

User avatar
DuyMinh
Posts: 40
Joined: 05 May 2017, 08:34

Re: AHK_H v2 beta

Post by DuyMinh » 09 Aug 2021, 22:42

@arcticir
@thqby
Thank you, I find some thread function in HotkeyIt github, i will try it with your version... :D

arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: AHK_H v2 beta

Post by arcticir » 13 Aug 2021, 04:48

It's been half a month :beard:

User avatar
thqby
Posts: 560
Joined: 16 Apr 2021, 11:18
Contact:

Re: AHK_H v2 beta

Post by thqby » 18 Aug 2021, 07:36

@DuyMinh Did you run the thread lib functions? This is ThreadObj, but I failed to compile with ahk2exe because A_LineFile did not parse correctly.

Code: Select all

;@Ahk2Exe-AddResource %A_LineFile%, THREADOBJ
class ThreadObj {
	static Call(script, cmdLine := "", title := "") {
		ThreadID := NewThread("#include '" (A_IsCompiled ? "*THREADOBJ" : A_LineFile) "'`nNumPut(`"PTR`",ObjShare({base:ThreadObj.Prototype})," GetVar(pObjShare := 0) ")`nSetEvent(" hEvent := CreateEvent() ")`n" script, cmdLine, title)
		WaitForSingleObject(hEvent, 1000), CloseHandle(hEvent)
		return pObjShare ? ObjShare(pObjShare) : ""
	}
	__Get(k, p) => p.Length ? %k%[p*] : %k%
	__Set(k, p, v) {
		global
		return p.Length ? (%k%[p*] := v) : (%k% := v)
	}
	PostCall(func, p*) => SetTimer(%func%.Bind(p*), -1)
	Call(func, p*) => %func%(p*)
	__Delete() {
		if (A_MainThreadID != A_ThreadID)
			SetTimer(ExitApp, -1)
	}
	FuncPtr(func) {
		static FindFunc := DynaCall(GetProcAddress(0, "ahkFindFunc"), "ut==sui", , A_ThreadID)
		return FindFunc(func)
	}
	LabelPtr(label) {
		static FindLabel := DynaCall(GetProcAddress(0, "ahkFindLabel"), "ut==sui", , A_ThreadID)
		return FindLabel(label)
	}
	Exec(code) {
		static ahkExec := DynaCall(GetProcAddress(0, "ahkExec"), "i==sui", , A_ThreadID)
		ahkExec(code)
	}
	AddScript(script, execute := 0) {
		static addScript := DynaCall(GetProcAddress(0, "addScript"), "ut==siui", , , A_ThreadID)
		return addScript(script, execute)
	}
	AddFile(file, execute := 0) {
		static addFile := DynaCall(GetProcAddress(0, "addFile"), "ut==siui", , , A_ThreadID)
		return addFile(file, execute)
	}
}

ObjShare(ObjorLresult) {
	static IDispatch := Buffer(16), init := NumPut("int64", 0x20400, "int64", 0x46000000000000c0, IDispatch)
	if IsObject(ObjorLresult)
		return LresultFromObject(IDispatch.Ptr, 0, ObjPtr(ObjorLresult))
	else if ObjectFromLresult(ObjorLresult, IDispatch.Ptr, 0, getvar(com := 0))
		throw Error("LResult Object could not be created", -1)
	return ComValue(9, com, 1)
}

User avatar
DuyMinh
Posts: 40
Joined: 05 May 2017, 08:34

Re: AHK_H v2 beta

Post by DuyMinh » 19 Aug 2021, 18:43

thqby wrote:
18 Aug 2021, 07:36
@DuyMinh Did you run the thread lib functions? This is ThreadObj, but I failed to compile with ahk2exe because A_LineFile did not parse correctly.

Code: Select all

;@Ahk2Exe-AddResource %A_LineFile%, THREADOBJ
class ThreadObj {
	static Call(script, cmdLine := "", title := "") {
		ThreadID := NewThread("#include '" (A_IsCompiled ? "*THREADOBJ" : A_LineFile) "'`nNumPut(`"PTR`",ObjShare({base:ThreadObj.Prototype})," GetVar(pObjShare := 0) ")`nSetEvent(" hEvent := CreateEvent() ")`n" script, cmdLine, title)
		WaitForSingleObject(hEvent, 1000), CloseHandle(hEvent)
		return pObjShare ? ObjShare(pObjShare) : ""
	}
	__Get(k, p) => p.Length ? %k%[p*] : %k%
	__Set(k, p, v) {
		global
		return p.Length ? (%k%[p*] := v) : (%k% := v)
	}
	PostCall(func, p*) => SetTimer(%func%.Bind(p*), -1)
	Call(func, p*) => %func%(p*)
	__Delete() {
		if (A_MainThreadID != A_ThreadID)
			SetTimer(ExitApp, -1)
	}
	FuncPtr(func) {
		static FindFunc := DynaCall(GetProcAddress(0, "ahkFindFunc"), "ut==sui", , A_ThreadID)
		return FindFunc(func)
	}
	LabelPtr(label) {
		static FindLabel := DynaCall(GetProcAddress(0, "ahkFindLabel"), "ut==sui", , A_ThreadID)
		return FindLabel(label)
	}
	Exec(code) {
		static ahkExec := DynaCall(GetProcAddress(0, "ahkExec"), "i==sui", , A_ThreadID)
		ahkExec(code)
	}
	AddScript(script, execute := 0) {
		static addScript := DynaCall(GetProcAddress(0, "addScript"), "ut==siui", , , A_ThreadID)
		return addScript(script, execute)
	}
	AddFile(file, execute := 0) {
		static addFile := DynaCall(GetProcAddress(0, "addFile"), "ut==siui", , , A_ThreadID)
		return addFile(file, execute)
	}
}

ObjShare(ObjorLresult) {
	static IDispatch := Buffer(16), init := NumPut("int64", 0x20400, "int64", 0x46000000000000c0, IDispatch)
	if IsObject(ObjorLresult)
		return LresultFromObject(IDispatch.Ptr, 0, ObjPtr(ObjorLresult))
	else if ObjectFromLresult(ObjorLresult, IDispatch.Ptr, 0, getvar(com := 0))
		throw Error("LResult Object could not be created", -1)
	return ComValue(9, com, 1)
}
I try but dont success to run cuz many syntax error from hotkeyit lib function. I try to fix, but so diffcult with me... :(

crocodile
Posts: 116
Joined: 28 Dec 2020, 13:41

Re: AHK_H v2 beta

Post by crocodile » 26 Aug 2021, 17:14

@thqby
Can you explain the two new functions MinHookEnable and MinHookDisable, or add some examples? Thanks.

User avatar
thqby
Posts: 560
Joined: 16 Apr 2021, 11:18
Contact:

Re: AHK_H v2 beta

Post by thqby » 26 Aug 2021, 22:28

@crocodile

Code: Select all

MinHookEnable := DynaCall(A_AhkPath '\MinHookEnable', 't==ttt*')
MinHookDisable := DynaCall(A_AhkPath '\MinHookDisable', 'ui==t')

pMessageBox := GetProcAddress(GetModuleHandle('user32'), 'MessageBoxW')
pHook := MinHookEnable(pMessageBox, CallbackCreate(hook_msgbox), &true_messagebox := 0)
MsgBox('hello world', 'ahk')
MinHookDisable(pHook)
MsgBox('hello world', 'ahk')

hook_msgbox(hwnd,text,title,opts) {
    DllCall(true_messagebox, 'ptr', 0, 'str', 'hook msgbox`n' StrGet(text), 'str', 'hook msgbox', 'uint', 0)
}

Post Reply

Return to “Ask for Help”