Stuck with simple problem Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Leli196
Posts: 216
Joined: 29 Aug 2015, 05:47
Location: Germany

Stuck with simple problem

15 Nov 2018, 16:33

Hi there,

I haven't done AHK for a while and now I am stuck with a simple problem:

Code: Select all

; INI file
[general]
var1 = some text
scheme = {Tab}var1

Code: Select all

; AHK code
IniRead, temp_ini, % A_WorkingDir "\settings.ini", general
Loop, Parse, temp_ini, `r`n
	value := StrSplit(A_LoopField, "="), var := value[1], %var% := value[2]

F1::
SendInput, %scheme%
Return
I want to send {Tab}some text with F1, but currently I do not know what I should do. I feel like a total noob, but the solution (or a solution) does not come to my mind.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Stuck with simple problem

15 Nov 2018, 17:18

did u write ur INI with those spaces around the = signs?
either delete them or use var := Trim(value[1])
Leli196
Posts: 216
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: Stuck with simple problem

15 Nov 2018, 21:20

Yes, I always use spaces before and after =. I thought it does not make a difference. At least in this case it does not change anything.
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: Stuck with simple problem

15 Nov 2018, 21:41

I think you're complicating it a bit,by parsing ini instead of reading every var from it... but you can do it this way...

Code: Select all

; AHK code
;IniRead, temp_ini, % A_WorkingDir "\settings.ini", general

temp_ini=		;to simplify test...
(
var1 = some text
scheme = {Tab}
)

MsgBox % scheme := StrSplit(StrSplit(temp_ini,"`n")[2]," = ")[2]
				. StrSplit(StrSplit(temp_ini,"`n")[1]," = ")[2]

F1::
SendInput, %scheme%
Return
live ? long & prosper : regards
Leli196
Posts: 216
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: Stuck with simple problem

16 Nov 2018, 17:00

That works, but then the scheme effectively is coded in the AHK code. I want the scheme in the Ini file.

What do mean with "instead of reading every var from it"? How do I just read every var from a Ini file?
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: Stuck with simple problem

17 Nov 2018, 00:49

Leli196 wrote:
16 Nov 2018, 17:00
That works, but then the scheme effectively is coded in the AHK code. I want the scheme in the Ini file.
I just did that for simplicity,perhaps this is a bit clearer...
>settings.ini

Code: Select all

var1 = some text
scheme = {Tab}
>script

Code: Select all

IniRead, temp_ini, % A_WorkingDir "\settings.ini", general
MsgBox % scheme := StrSplit(StrSplit(temp_ini,"`n")[2]," = ")[2]
				. StrSplit(StrSplit(temp_ini,"`n")[1]," = ")[2]
F1::
SendInput, %scheme%
Return
Leli196 wrote:
16 Nov 2018, 17:00
What do mean with "instead of reading every var from it"? How do I just read every var from a Ini file?
Either use IniRead for every var you intend to use:

Code: Select all

scheme := rINI("general","scheme") . rINI("general", "var1")
F2::SendInput, %scheme%
rINI(ini_section, ini_key, ini_file:="settings.ini"){
	IniRead, thisKey, %ini_file%, %ini_section%, %ini_key%
	Return ( thisKey != "ERROR" ? thisKey : "")
}
Or something like these:

https://autohotkey.com/board/topic/2551 ... -ini-file/
https://autohotkey.com/board/topic/6741 ... -ini-file/
live ? long & prosper : regards
Leli196
Posts: 216
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: Stuck with simple problem

26 Nov 2018, 13:21

Excuse the late reply.

I don't think you understand what I want to achieve. I want to send scheme with SendInput to a window. Scheme contains not only keypresses like {Tab} or {Enter}, but it shall also contain the contents of other variables, which are pieces of text.

Code: Select all

; INI file
[general]
var1 = some
var2 = text
var3 = for
var4 = example

scheme1 = {Tab}var1{Enter}var4
scheme2 = {Up}{Left}var2{Right}var3var4
scheme3 = var3{Enter}var2{Enter}

Code: Select all

; AHK code
IniRead, temp_ini, % A_WorkingDir "\settings.ini", general
Loop, Parse, temp_ini, `r`n
	value := StrSplit(A_LoopField, "="), var := value[1], %var% := value[2]

F1::
SendInput, %scheme1%
Return
So the way you suggested would require me to construct the scheme variables in the AHK code, which I do not want.

Edit:
So I could just do it like this, but I want the scheme vars in the INI file:

Code: Select all

; INI file
[general]
var1 = some
var2 = text
var3 = for
var4 = example

Code: Select all

; AHK code
IniRead, temp_ini, % A_WorkingDir "\settings.ini", general
Loop, Parse, temp_ini, `r`n
	value := StrSplit(A_LoopField, "="), var := value[1], %var% := value[2]

F1::
scheme1 := "{Tab}" var1 "{Enter}" var4
scheme2 := "{Up}{Left}" var2 "{Right}" var3 var4
scheme3 := var3 "{Enter}" var2 "{Enter}"
SendInput, %scheme1%
Return
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: Stuck with simple problem  Topic is solved

26 Nov 2018, 21:55

Ahh, that's easy enough...

Code: Select all

[general]
var1 = some text
scheme = var1 {Tab} var2 var3
var2 = some more text
var3 = .

Code: Select all

MsgBox % scheme := rINI("general","scheme")
F2::SendInput, %scheme%

;for var's referenced in key's to autoexpand, they must be space delimited...
rINI(ini_section, ini_key, ini_file:="settings.ini", callBackFlag:=""){
	IniRead, thisKey, %ini_file%, %ini_section%, %ini_key%
	thisKey :=  thisKey <> "ERROR" ? thisKey : ""
	If callBackFlag ;for internal use to validate ini key values...
		Return thisKey
	;Expand variables inside ini key that was read...
	For k,v in StrSplit(thisKey, A_Space)
		retVal .= (thisV:=rINI(ini_section,v,ini_file,true)) ? " " thisV " " : " " v " "
	Return Trim(retVal)
}

live ? long & prosper : regards
Leli196
Posts: 216
Joined: 29 Aug 2015, 05:47
Location: Germany

Re: Stuck with simple problem

02 Dec 2018, 20:45

Alright, thanks a lot.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, jaka1, metallizer, rc76, Rohwedder and 310 guests