How to incorporate .ini files? (Help please)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

How to incorporate .ini files? (Help please)

06 May 2019, 11:19

Can someone help me with .ini files? I have no idea what i'm doing.
I want to include 3 files along with the AHK script that will allow the user to customize the hotkeys in "ra" "sh" "fe" etc. "1,2,3,4 etc." instead they can make it to something they would like other than 1,2,3,4 etc. for each image. Then the scan area customize-able and user changeable (static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight), last but not least the hotkey for activation. In this case it's 1 "*1::SetTimer WatchSpells, 10" "*1 Up::SetTimer WatchSpells, Off"
If I could get pointed in the right direction I would greatly appreciate it as I have no clue how to work this!

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
, SPELL_KEYMAP := {"ra": "1"
, "sh": "2"
, "fe": "3"
, "re": "4"
, "ri": "5"
, "th": "6"
, "ti": "7"}

for spell, key in SPELL_KEYMAP
{
ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
if !ErrorLevel
Send % key
}
}
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: How to incorporate .ini files? (Help please)

06 May 2019, 16:07

Please take a look at the help manual. There is a file command that allows to integrate a file into an executable.
If you do not want to compile your script you can use the script itself also as an ini file
ciao
toralf
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to incorporate .ini files? (Help please)

06 May 2019, 18:55

First, create the INI files, like so:

Code: Select all

[SPELL_KEYMAP]
ra=1
sh=2
fe=3
re=4
ri=5
th=6
ti=7
Name that file SPELL_KEYMAP.ini (or change the filename in the following). Then, you could use the following to read all of the values at once:

Code: Select all

IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := []								; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
{
  Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
  SPELL_KEYMAP[Array[1]] := Array[2]			; Add the values to the SPELL_KEYMAP array
}
That will create the SPELL_KEYMAP array for you.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: How to incorporate .ini files? (Help please)

06 May 2019, 19:40

I shoud mention the following a one-liner string hack by Helgef:

Code: Select all

SetWorkingDir % A_ScriptDir
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	
SPELL_KEYMAP := Object(StrSplit(SPELLS, ["=", "`n"])*)
MsgBox % SPELL_KEYMAP.re
my scripts
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: How to incorporate .ini files? (Help please)

06 May 2019, 23:02

A_AhkUser wrote:
06 May 2019, 19:40
I shoud mention the following a one-liner string hack by Helgef:

Code: Select all

SetWorkingDir % A_ScriptDir
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	
SPELL_KEYMAP := Object(StrSplit(SPELLS, ["=", "`n"])*)
MsgBox % SPELL_KEYMAP.re
[EDIT] The Hotkey command allows you to create hotkeys whose key names are not known until after the script has started running:

Code: Select all

SetWorkingDir % A_ScriptDir
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ;  read all keys from the SPELL_KEYMAP section into a single string.
SPELL_KEYMAP := Object(StrSplit(SPELLS, ["=", "`n"])*) ; get an associative array from the string by splitting it using '=' and '`n' (the linefeed character) as delimiters.

Hotkey % "*" . SPELL_KEYMAP.ra, enableTimer, On ; create a hotkey, using the relevant key's value of the associative array as the hotkey's activation key.
Hotkey % "*" . SPELL_KEYMAP.sh, disableTimer, On
return

enableTimer:
SetTimer WatchSpells, 10
return

disableTimer:
SetTimer WatchSpells, Off
return

WatchSpells() {
static _i := 0
	ToolTip % ++_i
	; your code...
}
my scripts
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to incorporate .ini files? (Help please)

06 May 2019, 23:18

A_AhkUser wrote:
06 May 2019, 19:40
I shoud mention the following a one-liner string hack by Helgef:

Code: Select all

SetWorkingDir % A_ScriptDir
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	
SPELL_KEYMAP := Object(StrSplit(SPELLS, ["=", "`n"])*)
MsgBox % SPELL_KEYMAP.re
That's quite nifty. I didn't realize that you could use Object that way. I'll have to remember that. It essentially replaces my 7 lines with only 2 lines. I love efficiency like that. Thanks for sharing.
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

Re: How to incorporate .ini files? (Help please)

09 May 2019, 14:02

Osprey wrote:
06 May 2019, 18:55
First, create the INI files, like so:

Code: Select all

[SPELL_KEYMAP]
ra=1
sh=2
fe=3
re=4
ri=5
th=6
ti=7
Name that file SPELL_KEYMAP.ini (or change the filename in the following). Then, you could use the following to read all of the values at once:

Code: Select all

IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := []								; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
{
  Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
  SPELL_KEYMAP[Array[1]] := Array[2]			; Add the values to the SPELL_KEYMAP array
}
That will create the SPELL_KEYMAP array for you.
What line of code do I delete from my previous code in order to make this work?
Do I delete the following below from the original script I posted?
{"ra": "1"
, "sh": "2"
, "fe": "3"
, "re": "4"
, "ri": "5"
, "th": "6"
, "ti": "7"}

I have made the ini file and put it in the same folder as the ahk script. I also added your code right below CoordMode Pixel
IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP ; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := [] ; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n" ; Loop through the string one line at a time
{
Array := StrSplit(A_LoopField, "=") ; Store the current line's values before and after the = sign
SPELL_KEYMAP[Array[1]] := Array[2] ; Add the values to the SPELL_KEYMAP array
}

Kind of confused with this. Sorry
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to incorporate .ini files? (Help please)

09 May 2019, 18:05

Yes, just remove your SPELL_KEYMAP := {stuff} assignment and put the code that I gave (or the simpler code that A_AhkUser gave) below it, like so:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
    static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight

    IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
    SPELL_KEYMAP := []								; Create the SPELL_KEYMAP array
    Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
    {
        Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
        SPELL_KEYMAP[Array[1]] := Array[2]			; Add the values to the SPELL_KEYMAP array
    }

    for spell, key in SPELL_KEYMAP
    {
        ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
        if !ErrorLevel
            Send % key
    }
}
Actually, it looks like you can probably simplify your code even further by combining the Loop and For loops, like so:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
    static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight

    IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
    Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
    {
        Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
        ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" Array[1] ".png"
        if !ErrorLevel
            Send % Array[2]
    }
}
I would do that only if you don't have any other use for the SPELL_KEYMAP array elsewhere in your script (since we're not creating it in the interest of code efficiency). If you're not sure and want to play it safe, use the longer, first example, instead.
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

Re: How to incorporate .ini files? (Help please)

10 May 2019, 15:40

Osprey wrote:
09 May 2019, 18:05
Yes, just remove your SPELL_KEYMAP := {stuff} assignment and put the code that I gave (or the simpler code that A_AhkUser gave) below it, like so:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
    static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight

    IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
    SPELL_KEYMAP := []								; Create the SPELL_KEYMAP array
    Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
    {
        Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
        SPELL_KEYMAP[Array[1]] := Array[2]			; Add the values to the SPELL_KEYMAP array
    }

    for spell, key in SPELL_KEYMAP
    {
        ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
        if !ErrorLevel
            Send % key
    }
}
Actually, it looks like you can probably simplify your code even further by combining the Loop and For loops, like so:

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
    static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight

    IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
    Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
    {
        Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
        ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" Array[1] ".png"
        if !ErrorLevel
            Send % Array[2]
    }
}
I would do that only if you don't have any other use for the SPELL_KEYMAP array elsewhere in your script (since we're not creating it in the interest of code efficiency). If you're not sure and want to play it safe, use the longer, first example, instead.
This has helped me so much, I went with the first code you sent as I wasn't sure and played it safe. I'm seeing that I can't add a = sign after the = for the script to recognize the hotkey for it. Is there a work around for that or do I just have to use another key? I tried {=} but that didn't work.

Also can I apply this sort of code in order to have a custom screen area instead of fixed at A_screenwidth A_screenheight? Maybe an .ini file for the static search as well? If you could show me that code I would be even more appreciative than I am right now :facepalm: :D
Seriously thank you for the time you have put in to help me!
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to incorporate .ini files? (Help please)

10 May 2019, 19:57

If you mean that you're trying to do something like ra== in your INI file and it's not working, try replacing the Array := StrSplit(A_LoopField, "=") line with Array := StrSplit(A_LoopField, "=", , 2).

Yes, you can make the display area customizable according to values in an INI file. You can just add a section to your SPELL_KEYMAP.INI, like:

Code: Select all

[General]
X1=0
Y1=0
X2=-1	; -1 means use the screen width
Y2=-1	; -1 means use the screen height
...and then add a few IniRead lines...

Code: Select all

IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
    X2 := A_ScreenWidth
If(Y2 = -1)
    Y2 := A_ScreenHeight
...in place of your X1, Y1, X2 and Y2 assignments. You could do a loop like before, but maybe it's best to show you how to do it like this, so that it's less confusing and you can better adapt it, yourself.
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

Re: How to incorporate .ini files? (Help please)

10 May 2019, 22:02

That worked for the hotkeys having ra==, now they work perfectly!

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
    static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight

    IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
    SPELL_KEYMAP := []								; Create the SPELL_KEYMAP array
    Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
    {
        Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
        SPELL_KEYMAP[Array[1]] := Array[2]			; Add the values to the SPELL_KEYMAP array
    }

    for spell, key in SPELL_KEYMAP
    {
        ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
        if !ErrorLevel
            Send % key
    }
}
Where do I put this code in the above code and what do I delete? Sorry im confused again just like the last time. Do I delete static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight and replace it with the the code below?

Code: Select all

IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
    X2 := A_ScreenWidth
If(Y2 = -1)
    Y2 := A_ScreenHeight
Also, is this the correct format for the ini file for both the x1y1x2y2 custom area AND the custom hotkeys for the spells?

Code: Select all

[SPELL_KEYMAP]
ra=8
sh=+{F2}
fe=-
re=6
ri=7
th=8
ti=9
fl=+{F2}

[General]
X1=0
Y1=0
X2=-1	; -1 means use the screen width
Y2=-1	; -1 means use the screen height
I really appreciate all the help
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

Re: How to incorporate .ini files? (Help please)

11 May 2019, 10:15

Osprey wrote:
10 May 2019, 19:57
If you mean that you're trying to do something like ra== in your INI file and it's not working, try replacing the Array := StrSplit(A_LoopField, "=") line with Array := StrSplit(A_LoopField, "=", , 2).

Yes, you can make the display area customizable according to values in an INI file. You can just add a section to your SPELL_KEYMAP.INI, like:

Code: Select all

[General]
X1=0
Y1=0
X2=-1	; -1 means use the screen width
Y2=-1	; -1 means use the screen height
...and then add a few IniRead lines...

Code: Select all

IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
    X2 := A_ScreenWidth
If(Y2 = -1)
    Y2 := A_ScreenHeight
...in place of your X1, Y1, X2 and Y2 assignments. You could do a loop like before, but maybe it's best to show you how to do it like this, so that it's less confusing and you can better adapt it, yourself.
Also do you have a PP anywhere? I'd love to give you some $$ for the help
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to incorporate .ini files? (Help please)

11 May 2019, 15:43

Yes, put it in place of your X1, Y1, X2 and Y2 assignments. Your INI file looks correct, as well.

Thanks, but my help is free.
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

Re: How to incorporate .ini files? (Help please)

12 May 2019, 15:12

Osprey wrote:
11 May 2019, 15:43
Yes, put it in place of your X1, Y1, X2 and Y2 assignments. Your INI file looks correct, as well.

Thanks, but my help is free.

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
    X2 := A_ScreenWidth
If(Y2 = -1)
    Y2 := A_ScreenHeight

    IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
    SPELL_KEYMAP := []								; Create the SPELL_KEYMAP array
    Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
    {
        Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
        SPELL_KEYMAP[Array[1]] := Array[2]			; Add the values to the SPELL_KEYMAP array
    }

    for spell, key in SPELL_KEYMAP
    {
        ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
        if !ErrorLevel
            Send % key
    }
}
Is this what is should look like? I removed the code below and pur the iniread code in. I'm not sure I did it right though

Code: Select all

static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

Re: How to incorporate .ini files? (Help please)

13 May 2019, 12:24

Osprey wrote:
11 May 2019, 15:43
Yes, put it in place of your X1, Y1, X2 and Y2 assignments. Your INI file looks correct, as well.

Thanks, but my help is free.
Definitely not understanding how to do the custom area, sorry brand new to this stuff
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: How to incorporate .ini files? (Help please)

14 May 2019, 00:46

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode, Pixel, Screen

INI_FILE := A_ScriptDir "\mySettings.ini"
if not (FileExist(INI_FILE))
	FileAppend,
	(LTrim Join`n
	[area]
	x1=0
	y1=0
	x2=-1
	y2=-1
	[keymap]
	ra=1
	sh=2
	fe=3
	re=4
	ri=5
	th=6
	ti=7
	[hotkey]
	keyName=1
	), % INI_FILE, UTF-16
IniRead, hotkey, % INI_FILE, hotkey, keyName
Hotkey % "*" . hotkey, setTimer, On
IniRead, coordinates, % INI_FILE, area
data := StrSplit(coordinates, ["=", "`n"])
i := 0
Loop % data.count()/2 {
	k := data[ ++i ], v := data[ ++i ]
	if (v = -1) {
		substr := SubStr(k, 1, 1)
		SysGet, v, % Ord(substr) - Ord("x")
		area%k% := v
	} else area%k% := v
}
oKeymap := []
IniRead, keymap, % INI_FILE, keymap
Loop, Parse, keymap, "`n"
	ObjRawSet(oKeymap, StrSplit(A_LoopField, "=")*)
return

setTimer:
	SetTimer, watchSpells, 10
	KeyWait % hotkey
	SetTimer, watchSpells, Off
return

watchSpells:
	for spell, key in oKeymap
	{
		ImageSearch,,, % areax1, % areay1, % areax2, % areay2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
		if (!ErrorLevel)
			send % key
	}
return
not tested. Hope this helps.
@admin It took me ten minutes to post the code.... I could not posted it without being blocked until I used the temp variable substr instead of SubStr(k, 1, 1) @ SysGet, v, % Ord(substr) - Ord("x")... :headwall: :headwall:
my scripts
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

Re: How to incorporate .ini files? (Help please)

14 May 2019, 02:22

A_AhkUser wrote:
14 May 2019, 00:46

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode, Pixel, Screen

INI_FILE := A_ScriptDir "\mySettings.ini"
if not (FileExist(INI_FILE))
	FileAppend,
	(LTrim Join`n
	[area]
	x1=0
	y1=0
	x2=-1
	y2=-1
	[keymap]
	ra=1
	sh=2
	fe=3
	re=4
	ri=5
	th=6
	ti=7
	[hotkey]
	keyName=1
	), % INI_FILE, UTF-16
IniRead, hotkey, % INI_FILE, hotkey, keyName
Hotkey % "*" . hotkey, setTimer, On
IniRead, coordinates, % INI_FILE, area
data := StrSplit(coordinates, ["=", "`n"])
i := 0
Loop % data.count()/2 {
	k := data[ ++i ], v := data[ ++i ]
	if (v = -1) {
		substr := SubStr(k, 1, 1)
		SysGet, v, % Ord(substr) - Ord("x")
		area%k% := v
	} else area%k% := v
}
oKeymap := []
IniRead, keymap, % INI_FILE, keymap
Loop, Parse, keymap, "`n"
	ObjRawSet(oKeymap, StrSplit(A_LoopField, "=")*)
return

setTimer:
	SetTimer, watchSpells, 10
	KeyWait % hotkey
	SetTimer, watchSpells, Off
return

watchSpells:
	for spell, key in oKeymap
	{
		ImageSearch,,, % areax1, % areay1, % areax2, % areay2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
		if (!ErrorLevel)
			send % key
	}
return
not tested. Hope this helps.
@admin It took me ten minutes to post the code.... I could not posted it without being blocked until I used the temp variable substr instead of SubStr(k, 1, 1) @ SysGet, v, % Ord(substr) - Ord("x")... :headwall: :headwall:
Thanks for the help but Im wondering how to implement the ini read code that the above was sent to me, would you by any chance be able to help me place that ini read code in ?
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: How to incorporate .ini files? (Help please)

14 May 2019, 15:33

blickeddd wrote:
14 May 2019, 02:22
Thanks for the help but Im wondering how to implement the ini read code that the above was sent to me, would you by any chance be able to help me place that ini read code in ?
Have you run it? It should do all the stuff. After running it, you will in all likelihood find an ini file called mySettings.ini, in the script's own directory.
Osprey wrote:
06 May 2019, 23:18
That's quite nifty. I didn't realize that you could use Object that way. I'll have to remember that. It essentially replaces my 7 lines with only 2 lines. I love efficiency like that. Thanks for sharing.
@Osprey You're welcolme ;) I'm glad you like it. Although it appeared no to be a solution here (= possibly used as value). You might also be intersted in string hacks. Cheers
my scripts
blickeddd
Posts: 27
Joined: 06 May 2019, 11:12

Re: How to incorporate .ini files? (Help please)

14 May 2019, 16:44

A_AhkUser wrote:
14 May 2019, 15:33
blickeddd wrote:
14 May 2019, 02:22
Thanks for the help but Im wondering how to implement the ini read code that the above was sent to me, would you by any chance be able to help me place that ini read code in ?
Have you run it? It should do all the stuff. After running it, you will in all likelihood find an ini file called mySettings.ini, in the script's own directory.
Osprey wrote:
06 May 2019, 23:18
That's quite nifty. I didn't realize that you could use Object that way. I'll have to remember that. It essentially replaces my 7 lines with only 2 lines. I love efficiency like that. Thanks for sharing.
@Osprey You're welcolme ;) I'm glad you like it. Although it appeared no to be a solution here (= possibly used as value). You might also be intersted in string hacks. Cheers
I'm trying to have no values in the script and let the user set their own from the ini file. @Osprey gave me the code I was looking for to implement into my script. It is very clean and was wondering how to use it in my own

This code below

Code: Select all

IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
    X2 := A_ScreenWidth
If(Y2 = -1)
    Y2 := A_ScreenHeight
Implemented into this code below

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
CoordMode Pixel

*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off

WatchSpells() {
    static X1 := 0, Y1 := 0, X2 := A_ScreenWidth, Y2 := A_ScreenHeight

    IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
    SPELL_KEYMAP := []								; Create the SPELL_KEYMAP array
    Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
    {
        Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
        SPELL_KEYMAP[Array[1]] := Array[2]			; Add the values to the SPELL_KEYMAP array
    }

    for spell, key in SPELL_KEYMAP
    {
        ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
        if !ErrorLevel
            Send % key
    }
}
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: How to incorporate .ini files? (Help please)

14 May 2019, 17:16

Code: Select all


IniRead, SPELLS, SPELL_KEYMAP.ini, SPELL_KEYMAP	; Read all keys from the SPELL_KEYMAP section into a single string
SPELL_KEYMAP := []								; Create the SPELL_KEYMAP array
Loop, Parse, SPELLS, "`n"						; Loop through the string one line at a time
{
	Array := StrSplit(A_LoopField, "=")			; Store the current line's values before and after the = sign
	SPELL_KEYMAP[Array[1]] := Array[2]			; Add the values to the SPELL_KEYMAP array
}
IniRead, X1, SPELL_KEYMAP.ini, General, X1
IniRead, Y1, SPELL_KEYMAP.ini, General, Y1
IniRead, X2, SPELL_KEYMAP.ini, General, X2
IniRead, Y2, SPELL_KEYMAP.ini, General, Y2
If(X2 = -1)
    X2 := A_ScreenWidth
If(Y2 = -1)
    Y2 := A_ScreenHeight
*1::SetTimer WatchSpells, 10
*1 Up::SetTimer WatchSpells, Off
return

WatchSpells:
for spell, key in SPELL_KEYMAP
{
	ImageSearch, , , X1, Y1, X2, Y2, % "C:\Users\Abex\Documents\d.f\" spell ".png"
	if !ErrorLevel
		Send % key
}
return
(not tested).
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo and 215 guests