KeyWait unresponsive / delayed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
M_L
Posts: 13
Joined: 21 Mar 2016, 06:54

KeyWait unresponsive / delayed

05 Nov 2018, 03:45

Namaste @all,
I use KeyWait to detect long key presses.
Problem is: if I don't do a long press, hence press and release it quickly, it stills delays the processing. I would expect that on release it instantly sends my commands, without any delay whatsoever. The result is that the characters I type are jumbled, because the processing of my long-press keys is delayed.

My concrete case is the following: q key produces a q when pressed normally but an @-sign on long press

Code: Select all

$q::OnLongPress(SubStr(A_ThisHotkey, 2), "@")

OnLongPress(PressedKey, CharToWrite) {
	KeyWait, %PressedKey%, T0.3
	if ErrorLevel{
		SendInput {%CharToWrite%}
	} else{
		SendInput {%PressedKey%}
	}
	KeyWait, %PressedKey%,
}
Any idea how else I could progamm a character-key to behave differently on long-press, but still retain its responsive qualities when I type normally?
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: KeyWait unresponsive / delayed

05 Nov 2018, 07:25

Not sure why your code doesn't work, but this should:

Code: Select all

$F7::
	KeyWait, F7, T1.0
	if ErrorLevel
		{
			;long
			MsgBox, long
		}
	else
		{
			KeyWait, F7, D T0.01
				if ErrorLevel
					;short
					MsgBox, short
		}
	return
Edit: Hm, not sure where the crappy syntax came from, looks fine in the editor. :think:
M_L
Posts: 13
Joined: 21 Mar 2016, 06:54

Re: KeyWait unresponsive / delayed

05 Nov 2018, 13:31

Thanks, your code is fine.
My problem is that KeyWait delays the SendInput so much that the letter q gets sends after the next letter I type. E.g. question would become uqestion.
I know where this problem stems from: from the fact that KeyWait waits until the key is realized and just after that sends the input. But this messes with the order of the typed characters. So I could type slower, so that I type the next letter only after the previous one is released. Obviously I don't like that... hence the question.
So if there ever is a way to do just that, message me! Until then, I will have to do what I want in a different way.
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: KeyWait unresponsive / delayed

06 Nov 2018, 07:39

You're not using 'D' option (KeyWait, q, D T0.5) in you code, which checks if the key is being pushed down for n seconds. That's why your code either delays the actual key you're pressing or firing the SendInput to quickly.

Edit:Hm, you're right, even if I set the delay on the short press to very very low I get a delay long enough for letters to be switched. Will try to find out if there's a solution. P.S.: SetBatchLines, -1 doesn't work.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 243 guests