How to log when a hotstring has been used?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
justcop
Posts: 5
Joined: 25 Jan 2019, 08:33

How to log when a hotstring has been used?

Post by justcop » 16 Jun 2021, 06:58

I have a long list of hotstrings in an ahk file.

I'm looking for a way to log every time one of them is used.

For example if my hotstring ahk programme contained the following

Code: Select all

::1::one

::2::two

::3::three
then if I were to type

Code: Select all

1 2 3
Then I would want to produce a text file with the following data with *TIMESTAMP* replaced by the actually timestamp of the time the hotstring was pressed

Code: Select all

*TIMESTAMP* 1
*TIMESTAMP* 2
*TIMESTAMP* 3
Now I'm aware that I could add a outputdebug or fileappend to every hotstring but I'm wondering if there's a more elegant solution that could work with any list of hotstrings.
Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How to log when a hotsting has been used?

Post by Rohwedder » 16 Jun 2021, 08:53

Hallo,
try:

Code: Select all

:X:1::X("one")
:X:2::X("two")
:X:3::X("three")
X(Replacement)
{
	SendInput,% Replacement
	HotString := SubStr(A_ThisHotkey,4)
	ToolTip,% "Hotstring: " Hotstring
}
Replace the Tooltip with a suitable Fileappend.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to log when a hotsting has been used?

Post by swagfag » 17 Jun 2021, 12:34

if u only got no context sensitive hotstrings(although it could be made to handle those as well) and ure too lazy to change them in source to implement the logging(as already shown) and ure fine with the following possibly(likely) breaking in a future update, u can hook before the hotstring checking subroutine:

Code: Select all

; offsets not guaranteed to work with other versions
; context sensitive hotstrings not supported
#Requires AutoHotkey v1.1.33.09

OnMessage(0x401, Func("OnHotstring")) ; AHK_HOTSTRING := (WM_USER := 0x400) + 1
OnHotstring(wParam, lParam, msg, hwnd) {
	static pHotstringSHS := NumGet(DllCall("GetModuleHandle", "Ptr", 0, "Ptr")
		+ ((A_PtrSize = 8) ? 0x1296A0 : (A_IsUnicode ? 0xD7F6C : 0xBAD14)), "Ptr") ; U64/U32/A32 offsets

	pHS := NumGet(pHotstringSHS + (wParam * A_PtrSize), "Ptr") ; hs = Hotstring::shs[msg.wParam];

	; class Hotstring
	; {
	; public:
	; 	LabelRef mJumpToLabel;
	; 	LPTSTR mName;
	; 	LPTSTR mString;
	; 	LPTSTR mReplacement;
	; 	HotkeyCriterion *mHotCriterion;
	; 	int mPriority;
	; 	int mKeyDelay;
	; 	...
	; }
	pmName := NumGet(pHS + (1 * A_PtrSize), "Ptr")
	name := StrGet(pmName)

	ToolTip % "do ur logging here`n`n" name
}

::btw::by the way
::al::airline
::CEO::Chief Executive Officer
justcop
Posts: 5
Joined: 25 Jan 2019, 08:33

Re: How to log when a hotsting has been used?

Post by justcop » 26 Aug 2022, 06:59

@swagfag Whilst my ahk coding volume has been significant, I'm only just revisiting this intended function after er.. somewhile. This code seems to launch correctly the onmessage but doesn't output the hotsting as the 'name' variable. Did this work for you in its current form?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to log when a hotsting has been used?

Post by swagfag » 30 Aug 2022, 06:17

if "current form" = AutoHotkey v1.1.33.09, yes. otherwise, who knows. there's a reason i wrote all these disclaimers and put that specific directive there. im not looking up the offsets for other versions. better fix ur script in code instead of relying on hacks like these
Post Reply

Return to “Ask for Help (v1)”