How to make a new line inside IniWrite every day? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
SirSocks
Posts: 183
Joined: 26 Oct 2018, 08:14

How to make a new line inside IniWrite every day?

06 Sep 2019, 12:59

Hello -

I am trying to track how many times I push F2 and F3. I would like to build a daily log of this information. Should I use IniWrite, FileAppend or some other method?
Question: How can i make a new line every day and log the total number of key presses?
I would like the information to be saved to a .txt or .ini file and appear something like this.....

(date) = ( Number of Keypress)
20190906 = 50
20190907 = 182
20190908 = 76

Here's some code that I started working on, but I'm not to sure how to make a new line every day.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance Force

Count := 1
Today := SubStr(A_Now, 1, 8) ; Date format YYYYMMDD 20190920

F2::
GoSub, Stats
return

F3::
GoSub, Stats
return

Stats:
FKeysPress := count++
IniWrite, %FKeysPress%,A_WorkingDir.ini	, %Today%, KeyPresses
return

esc::
msgbox, Number of time the F Keys was pushed = %FKeysPress%
return
Question: How can i make a new line every day and log the total number of key presses?

All help is appreciated, Thank you.
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: How to make a new line inside IniWrite every day?  Topic is solved

06 Sep 2019, 15:12

Edit: Updated

Code: Select all

#SingleInstance, Force

~F1 Up::
~F2 Up::
	Today := A_YYYY . A_MM . A_DD
	IniRead, KeyCount, Stats.ini, Stats, %Today%, 0
	KeyCount++
	IniWrite, %KeyCount%, Stats.ini, Stats, %Today%
return

F12::
	Total := 0

	IniRead, GetStats, Stats.ini, Stats

	Pos := 0
	While (Pos := RegExMatch(GetStats, "=(\d+)", Match, Pos + 1)) {
		Total += Match1
	}

	MsgBox, % Total
return
Last edited by TheDewd on 06 Sep 2019, 15:30, edited 3 times in total.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
SirSocks
Posts: 183
Joined: 26 Oct 2018, 08:14

Re: How to make a new line inside IniWrite every day?

06 Sep 2019, 15:19

If the script was running for several days the date would be incorrect. I reformat your code and to check the date on each keypress. Thanks once again @TheDewd :bravo:

Code: Select all

#SingleInstance, Force
#Persistent

KeyCount := 0

~F1::
~F2::
	KeyCount++
        Today := A_YYYY . A_MM . A_DD
	IniWrite, %KeyCount%, Stats.ini, Stats, %Today%
return
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: How to make a new line inside IniWrite every day?

06 Sep 2019, 15:21

@SirSocks,

Thank you! I updated my post, and added how to get the total keypresses from ALL days.
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: How to make a new line inside IniWrite every day?

06 Sep 2019, 15:26

I updated my post once again... Fixed a flaw that would reset the key count value to zero if you reload the script.

Also changed keys to F1 Up and F2 Up so it wouldn't repeatedly count if you held the keys down for a long time.

Looks good now!
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
User avatar
SirSocks
Posts: 183
Joined: 26 Oct 2018, 08:14

Re: How to make a new line inside IniWrite every day?

06 Sep 2019, 16:00

@TheDewd
Your coding is always too notch. Thank you very much for your time towards this.

Return to “Ask For Help”

Who is online

Users browsing this forum: benbory, boiler, leeblee, TXShooter, xolo and 298 guests