confused about #include

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
peter_ahk
Posts: 101
Joined: 13 Feb 2024, 14:49

confused about #include

21 Mar 2024, 03:25

hello folks i have a noob question, i am trying to understand a scenario with include and an exe

what i would like is to have the ability for people to add their own stuff to my tool (routines outside the design of my macro's)

so i did this below, however does this make sense when i run an exe having this in it? when i compile they are empty but will it add stuff to my "exe" when i add stuff to it after i compiled or am i completely missing the mark here?

Code: Select all

#Include, Include\addon1.ahk
#Include, Include\addon2.ahk
#Include, Include\addon3.ahk
User avatar
boiler
Posts: 16996
Joined: 21 Dec 2014, 02:44

Re: confused about #include

21 Mar 2024, 06:05

It does not work like you are describing. It will include whatever is in the specified files when it is compiled, and the the .exe file is set. When you run the .exe file, it does not process the #Include lines and pull in the files that were specified. Those #Include lines don’t exist anymore. They were replaced with the code that was in them at compile time. This is mentioned in the #Include documentation when describing how line numbering is affected:
#Include Remarks wrote:…except for compiled scripts, which merge their included files into one big script at the time of compilation
peter_ahk
Posts: 101
Joined: 13 Feb 2024, 14:49

Re: confused about #include

21 Mar 2024, 07:44

boiler wrote:
21 Mar 2024, 06:05
It does not work like you are describing. It will include whatever is in the specified files when it is compiled, and the the .exe file is set. When you run the .exe file, it does not process the #Include lines and pull in the files that were specified. Those #Include lines don’t exist anymore. They were replaced with the code that was in them at compile time. This is mentioned in the #Include documentation when describing how line numbering is affected:
#Include Remarks wrote:…except for compiled scripts, which merge their included files into one big script at the time of compilation
yeah i was afraid of that. thank you
User avatar
Chunjee
Posts: 1423
Joined: 18 Apr 2014, 19:05
Contact:

Re: confused about #include

21 Mar 2024, 09:18

If their changes can be described in configuration files like .json that could work. But very hard to describe code in configuration I imagine
peter_ahk
Posts: 101
Joined: 13 Feb 2024, 14:49

Re: confused about #include

21 Mar 2024, 09:25

Chunjee wrote:
21 Mar 2024, 09:18
If their changes can be described in configuration files like .json that could work. But very hard to describe code in configuration I imagine
i am afraid that is way over my head and would also miss the target user who knows nothing about all that (like me lol). I stick to my own preset system that can save any buttons settings to temp and then load it on another button combined with my export option i can easily help someone out then or have a bunch of files that can be dropped in to add stuff

thnx all
User avatar
Chunjee
Posts: 1423
Joined: 18 Apr 2014, 19:05
Contact:

Re: confused about #include

21 Mar 2024, 09:36

If you are just remapping buttons that would be pretty easy as a txt file or ini


I prefer json however
peter_ahk
Posts: 101
Joined: 13 Feb 2024, 14:49

Re: confused about #include

21 Mar 2024, 09:46

Chunjee wrote:
21 Mar 2024, 09:36
If you are just remapping buttons that would be pretty easy as a txt file or ini
I prefer json however
its a bit more see my buttons are all programmable macro's that could be anything thats possible with the commands i coded to work. And also all settings for color of text button itself hover over and position and more. in my experience its all i ever needed gui wise to design my own outside the script and some command wise but in those cases where someone would like to put their own complicated routine under a button that is outside my build in possibilities then one could. that was my idea

edit: forgot to say i have build in gosub option
User avatar
Chunjee
Posts: 1423
Joined: 18 Apr 2014, 19:05
Contact:

Re: confused about #include

21 Mar 2024, 12:09

just thinking out loud. It might look like:

Code: Select all

{
	"name": "Joe's Custom Plugin",
	"tasks": [
		"pressOne",
		"functionClose()",
		"pressEsc"
	],
	"hotkey": "w"
}

The downside is you have to code it twice in a way. Once to parse it and understand the input, then again to translate that input into hotkeys/actually do the thing.
peter_ahk
Posts: 101
Joined: 13 Feb 2024, 14:49

Re: confused about #include

21 Mar 2024, 12:20

Chunjee wrote:
21 Mar 2024, 12:09
just thinking out loud. It might look like:

Code: Select all

{
	"name": "Joe's Custom Plugin",
	"tasks": [
		"pressOne",
		"functionClose()",
		"pressEsc"
	],
	"hotkey": "w"
}
The downside is you have to code it twice in a way. Once to parse it and understand the input, then again to translate that input into hotkeys/actually do the thing.
haha yeah seams complicated to do that with a macro like this where i use the principle of where there is no info in the ini it wont use that command so it could be many things

Code: Select all

Macro1:
	SetBatchLines, -1
	IniWrite,1,settings\ButtonClickedNR.ini,setupinfo,NR
	IniWrite,3,settings\GuiInUseNR.ini,setupinfo,NR
	tempwindow := % IfWinExist[1]
	KeyDown:=A_TickCount
	Keywait, LButton
	Duration:=(A_TickCount-KeyDown)
If  (Duration<OpenOnWindow1)
	{	IfWinExist, % IfWinExist[1]
		{  	Start()
			WinActivate, % WinActivate[1]
			if IsLabel(GoSub[1])
			GoSub, % GoSub[1]
			FileRead, FileInMemoryNewLine,% FileReadNewLine[1]
			FileRead, FileInMemoryEndLine,% FileReadEndLine[1]
			Sleep,% Sleep1[1]
			Send, % Send1[1]
			FileAppend,%FileInMemoryNewLine%`n,% FileAppendNewLine[1]
			FileAppend,%FileInMemoryEndLine%   ,% FileAppendEndLine[1]
			WinMenuSelectItem,,,% WinMenuSelectItemMenu[1] , % WinMenuSelectItemSubMenu1[1] , % WinMenuSelectItemSubMenu2[1] , % WinMenuSelectItemSubMenu3[1] , % WinMenuSelectItemSubMenu4[1] , % WinMenuSelectItemSubMenu5[1] , % WinMenuSelectItemSubMenu6[1]
			ControlClick ,% ControlClick[1] ,,, % ControlClickMode[1]
			Sleep, % Sleep2[1]
			Send,   % Send2[1]
			SoundPlay, % SoundPlay[1]
			TrayTip,, % TrayTip[1], 1,16
			SetTimer, TrayTipOff, % TrayTipTimer[1]
			temponoff := % ProgressOnOff[1]
			if temponoff=on
				{tempprogress := % ProgressOptions[1]
				Progress,  b zh-1 %tempprogress%  , % ProgressText[1]
				SetTimer, ProgressOff, % ProgressTimer[1]
				} else {}
			Run, % Run[1]
			Send, % Send3[1]
			SetBatchLines, %SetBatchLines%
			return
		}
	}
	else If (Duration>OpenOnWindow1) and If (Duration<OpenOnWindow2)
			{ 	if IsLabel(GoSub1stWindow[1])
				GoSub, % GoSub1stWindow[1]
				SetBatchLines, %SetBatchLines%
				return
			}
	else If (Duration>OpenOnWindow2) and If (Duration<OpenOnWindow3)
			{   If IsLabel(GoSub1[1])
				GoSub, % GoSub1[1]
				Run, % RunOnHold1[1]
				SetBatchLines, %SetBatchLines%
				return
			}
	else If (Duration>OpenOnWindow3)
			{   if IsLabel(GoSub2[1])
				GoSub, % GoSub2[1]
				Run, % RunOnHold2[1]
				SetBatchLines, %SetBatchLines%
				return
			}
	else Abort()
return
and besides these options every button has adjustable font, font size, font color, font hover color, font pressed color. buttons have a default, a pressed and a hover color + an outside edge thats also user adjustable. oh and not to forget its width, height, x and y

maybe i should take the lessons from this project to the next version :D
william_ahk
Posts: 496
Joined: 03 Dec 2018, 20:02

Re: confused about #include

21 Mar 2024, 23:39

It is possible to do what you wanted. I wanted something similar earlier, here's a demonstration.

Runner.ahk:

Code: Select all

;@Ahk2Exe-Base %A_AhkPath%, Main.exe
;@Ahk2Exe-ResourceID #1
;@Ahk2Exe-AddResource *6 Main.ahk, MAIN_SCRIPT
#NoTrayIcon
#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

ScriptName := "Main"

ResRead(Code, "MAIN_SCRIPT")
Shell := ComObjCreate("WScript.Shell")
Name := "\\.\pipe\" ScriptName ".exe"
Pipe := []
Loop 2
{
	Pipe[A_Index] := DllCall("CreateNamedPipe"
	, "Str", Name
	, "UInt", 2, "UInt", 0
	, "UInt", 255, "UInt", 0
	, "UInt", 0, "UPtr", 0
	, "UPtr", 0, "UPtr")
}
Exec := Shell.Run("""" A_ScriptFullPath """ /restart /script /CP65001 " Name)
DllCall("ConnectNamedPipe", "UPtr", Pipe[1], "UPtr", 0)
DllCall("ConnectNamedPipe", "UPtr", Pipe[2], "UPtr", 0)
FileOpen(Pipe[2], "h", "UTF-8").Write(Code)
Loop 2
	DllCall("CloseHandle", "UPtr", Pipe[A_Index])

ExitApp

; SKAN http://www.autohotkey.com/board/topic/57631-crazy-scripting-resource-only-dll-for-dummies-36l-v07/?p=609282
ResRead( ByRef Var, Key )
{
  VarSetCapacity( Var, 128 ), VarSetCapacity( Var, 0 )
  If ! ( A_IsCompiled )
  {
    FileGetSize, nSize, %Key%
    FileRead, Var, *c %Key%
    Return nSize
  }
  If hMod := DllCall( "GetModuleHandle", UPtr,0 , Ptr)
    If hRes := DllCall( "FindResource", Uptr,hMod, Str,Key, UInt,6 , Ptr)
      If hData := DllCall( "LoadResource", UInt,hMod, UPtr,hRes , Ptr)
        If pData := DllCall( "LockResource", UInt,hData, Ptr )
        {
          VarSetCapacity( Var, nSize := DllCall( "SizeofResource", UInt,hMod, UInt,hRes ) )
          DllCall( "RtlMoveMemory", Str,Var, UInt,pData, UInt,nSize )
          Var := StrGet(&Var, nsize, "UTF-8")
          Return, StrLen(Var)
        }
  Return 0
}
Main.ahk: (will be statically embedded into the final exe)

Code: Select all

#Include *i Addon.ahk

Msgbox, Ayo
Addon.ahk: (can be dynamically written, not embedded into the final exe)

Code: Select all

SoundBeep, 300
The trick is to use the compiled exe as an AutoHotkey interpreter with the /script switch, this way you can run the script as if you're running the source file. To use, compile Runner.ahk instead of Main.ahk. Ahk2exe will embed Main.ahk into the compiled exe, but when it is run, the Main code embedded is executed dynamically, therefore including any ahk you want at runtime.
peter_ahk
Posts: 101
Joined: 13 Feb 2024, 14:49

Re: confused about #include

22 Mar 2024, 06:10

@william_ahk

thank you this is all very interesting knowing its possible i have so many questions haha but should really put in some time before i ask any. haha so much on my to do list.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AmDeG 11, Bing [Bot], Google [Bot] and 232 guests