InputHook() OnEnd returns 0

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
mslonik
Posts: 145
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

InputHook() OnEnd returns 0

23 Feb 2022, 13:44

Dear Forum,

for some reason InputHook() property OnEnd returns value 0. I don't understand why and/or what does it mean:
  1. I don't set any end keys (either by character code, either by keycode) but I get one.
  2. No character code or keycode is equal to 0.
My code which initializes InputHook() in quite extensive script:

Code: Select all

F_InitiateInputHook()
{
	global	;assume-global mode of operation

	v_InputH 			:= InputHook("V I1")			;I1 on purpose
,	v_InputH.OnChar 		:= Func("F_OneCharPressed")
,	v_InputH.OnKeyUp 		:= Func("F_BackspaceProcessing")
,	v_InputH.OnEnd		:= Func("F_InputHookOnEnd")
	v_InputH.KeyOpt("{Backspace}", "N")
	v_InputH.Start()
}
Initially I've assumed that with such InputHook() setup it will collect user's input indefinitely until I run v_InputH.Stop() somewhere in my code, which I don't actually.

It seems I was wrong, what I've investigated as follows:

Code: Select all

F_InputHookOnEnd(ih)	;for debugging purposes
{
	global	;assume-global mode of operation
	local 	KeyName := ""

	KeyHistory
	KeyName := ih.EndKey
	FileAppend, % A_Hour . ":" . A_Min . ":" . A_Sec . ":" . "|" . ++v_LogCounter . "|" . "OnEnd" . "|" . KeyName 
		. "|" . "GetKeyName:" 	. "|" . GetKeyName(KeyName) 
		. "|" . "GetKeyVK:" 		. "|" . GetKeyVK(KeyName)
		. "|" . "GetKeySC:" 		. "|" . GetKeySC(KeyName)
		. "|" . "`n", % v_LogFileName
	MsgBox, 48, % SubStr(A_ScriptName, 1, -4) . ":" . A_Space . TransA["error"], % "Input hook has unexpectedly finished its operation" . "`n`n" 
		. "KeyName:" . KeyName . "`n"
		. "More on that in log file:" . "`n"
		. v_LogFileName
}
And here is what I record in log each time F_InputHookOnEnd catches KeyName, what happens from my perspective in completely random moments and circumstances:

Code: Select all

10:30:48:|25|OnEnd||GetKeyName:||GetKeyVK:|0|GetKeySC:|0|
...
16:16:29:|28|OnEnd||GetKeyName:||GetKeyVK:|0|GetKeySC:|0|
Probably again I miss something in AutoHotkey documentation. Any help is appreciated.

Kind regards, mslonik (🐘)
Last edited by mslonik on 24 Feb 2022, 01:05, edited 1 time in total.

My scripts on this forum: Hotstrings Diacritic O T A G L E
Please become my patreon: Patreon👍
Written in AutoHotkey text replacement tool: Hotstrings.technology
Courses on AutoHotkey :ugeek:
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: InputHook() OnEnd returns 0

23 Feb 2022, 23:25

InputHook("V I1") sets up none of Endkeys. If I'm not mistaken.
InputHook := InputHook([Options, EndKeys, MatchList])
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
User avatar
mslonik
Posts: 145
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

Re: InputHook() OnEnd returns 0

24 Feb 2022, 01:04

Thank you for your reply @amateur+ .

Actually this is one of the cores of my problem:
  1. I don't set any end keys (either by character code, either by keycode) but I get one.
  2. No character code or keycode is equal to 0.
So what is actually happening and why?

I'll edit my first post to be more obvious, thank you for your suggestion.

My scripts on this forum: Hotstrings Diacritic O T A G L E
Please become my patreon: Patreon👍
Written in AutoHotkey text replacement tool: Hotstrings.technology
Courses on AutoHotkey :ugeek:
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: InputHook() OnEnd returns 0

24 Feb 2022, 01:44

What is EndReason? I guess that might be ih.EndReason="Max" and if so you can try InputHook("V L99999999"). I think I1 is a default option and you may omit it.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
User avatar
mslonik
Posts: 145
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

Re: InputHook() OnEnd returns 0

24 Feb 2022, 09:24

@amateur+ Thank you again for support. It's really appreciated and helpful.

To the core: EndReason always is set to Max.

This piece of information brings to me idea what is going on with my code:
could it be the case that each time new character "arrives" to InputHook buffer and handled by OnChar property it is not removed from input buffer, but stays there (forever)?

So should I actually "reset" InputHook buffer after handling any new character to protect it against overflow? (For example by applying Stop() and Start() methods).

Last, but not least, "I1" option is there on purpose: I do some "back feeding" in my script in some circumstances (thanks to SendLevel). By the way here is link to it.

Kind regards, mslonik (🐘)

My scripts on this forum: Hotstrings Diacritic O T A G L E
Please become my patreon: Patreon👍
Written in AutoHotkey text replacement tool: Hotstrings.technology
Courses on AutoHotkey :ugeek:
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: InputHook() OnEnd returns 0

24 Feb 2022, 11:37

I mean InputHook("V I1") is totally equivalent to InputHook("V").
Also you don't need to stop and start again. If InputHook("V L99999999") isn't sufficient for you, you may try InputHook("V L99999999999999999999999999999999999999999999999999999999999999999999999999999999") :D
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
User avatar
mslonik
Posts: 145
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

Re: InputHook() OnEnd returns 0

25 Feb 2022, 09:54

Yes, now I understand what's going on with my code and everything what I assume fits to facts which I get after running my code.

To sum up:
  • For InputHook even if L parameter (length) is not specified on time of initialization explicite, it is equal to 1023. In fact as you pointed out it can be of any length, but have to specified then. And this is clearly stated in the help information.
  • For my specific purpose even L0 would be fine what I realized after realizing what's wrong with my thinking.
  • The EndKey = 0 was not relevant in this particular situation. What should I pay attention to is EndReason, which was equal to Max.
My conclusion is that for some "human" reason I missed information which was actually provided in help.

@amateur+ thank you again for your patient support. I owe you 🍺 or multiple x 🍺 if you wish 😉

I consider this issue as closed.

My scripts on this forum: Hotstrings Diacritic O T A G L E
Please become my patreon: Patreon👍
Written in AutoHotkey text replacement tool: Hotstrings.technology
Courses on AutoHotkey :ugeek:
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: InputHook() OnEnd returns 0

25 Feb 2022, 11:49

Good work!
Thanks for beer buying offer :). But this issue wasn't a lot of time consuming for me and I was glad to help you to clear some things. Or you may buy a beer to @mikeyww, if you will insist on thanking me materially, since he among other active users (but I suppose that most of all of them) regularly provides tonnes of very qualitative help to newcomers and experienced users such as you.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, TAC109 and 75 guests