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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
SirSocks
Posts: 360
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: 1510
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.
User avatar
SirSocks
Posts: 360
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: 1510
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.
User avatar
TheDewd
Posts: 1510
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!
User avatar
SirSocks
Posts: 360
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 (v1)”

Who is online

Users browsing this forum: Google [Bot], haomingchen1998, xask1 and 237 guests