Typo on press\release

Get help with using AutoHotkey and its commands and hotkeys
CAH9t
Posts: 29
Joined: 15 Jul 2017, 11:12
Location: Land

Typo on press\release

07 Aug 2017, 00:56

Code: Select all

$SC028::
While getKeyState("SC028","P")!=0 
{
sleep 1
}
If (A_TimeSinceThisHotkey <200)   
sendInput, {SC028}
return 
I noted systematic typo in my writing
smbs'
(that's why I've christened it "smbs' problem" ;) ) when I use the code above.

Here's the conundrum. How to lose the typo?

Possible but not desirable workaround:
Dependable No-typo solution without sending extra keys (Cause I have one that sends SC028 instantly than deletes it if hold-time is long enough, but it messes the selection (selected text) anyway ) .

ps. I know that separating actions say on !SC028 would solve the problem, and I've already done it for the time being. But it's not a solution.
Last edited by CAH9t on 22 Sep 2017, 06:18, edited 3 times in total.
User avatar
Masonjar13
Posts: 1530
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: AHK has smbs' problem

07 Aug 2017, 06:16

I'm not entirely sure what you mean.. But getKeyState() produces little to no CPU time, unless you have some strange, slow drivers, but that would make normal typing slow as well.

I see you have sleep 1, which isn't really an option. Minimum sleep time is 10ms, if it's 1-9, it will set it to 10ms. You can use sleep 0, which doesn't actually produce a delay, rather, it allows another queued CPU task to run on the thread. Faster than 10ms, but won't freeze other applications, though it'll still be using more CPU time (obviously).

Code: Select all

$SC028::
while(!getKeyState("SC028","P"))
    sleep 0
if(a_timeSinceThisHotkey < 200)
    sendInput {SC028}
return
You may also want to look at SetBatchLines.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
CAH9t
Posts: 29
Joined: 15 Jul 2017, 11:12
Location: Land

Re: AHK has smbs' problem

11 Aug 2017, 09:08

Masonjar13 sleep 0 or sleep10 it doesn't matter result is the same, besides, you see that

Code: Select all

SC028::
keywait, SC028, 
If (A_TimeSinceThisHotkey <200)   
sendInput, {SC028}
return
has no visible delay so obviously your advice is beside the point. You may just try the code and try to type smb's real fast with it.

By the way, doing my study, I've already encountered the subj problem in ahk forums (so at least two people, except me, noticed it too), so it's not just me.

When I raised that question I thought it could be useful info for ahk development.

Cheers, lads.

ps.
don't be afraid of sc. You can test it with an ordinary key. I'm bilingual ( I have more than one K-layout so I don't use simple «l::»-type hotkeys)

Code: Select all

l::   ; don't be lazy try to type anything L-contaning real fast 
keywait, %A_ThisHotkey%, 
If (A_TimeSinceThisHotkey <200)   
sendInput, {%A_ThisHotkey%}
return
Last edited by CAH9t on 12 Sep 2017, 12:49, edited 2 times in total.
User avatar
evilC
Posts: 4791
Joined: 27 Feb 2014, 12:30

Re: AHK has smbs' problem

11 Aug 2017, 10:53

I am not really sure what you are trying to do, what is an "smb"?

Using KeyWait or GetKeyState to detect release of a key is the wrong way to do it - I tried to get them to remove it as an example from the docs, but to no avail :(
Use the up event

SC028 up::

Observe this code:

Code: Select all

F10::
F11::
	Tooltip %A_ThisHotkey% Down
	While (GetKeyState(A_ThisHotkey)){
		Sleep 10
	}
	Tooltip %A_ThisHotkey% Up
	return
Hold F10, then hold F11, then release F10.... Oops, does not work.

No such problem with this code:

Code: Select all

F10::
F10 up::
F11::
F11 up::
	Tooltip %A_ThisHotkey%
	return

Return to “Ask For Help”

Who is online

Users browsing this forum: kunkel321, Lord Junn, malcev, mikeyww, wineguy and 43 guests