Double Left -> Ctrl-Left – problem with the script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Ctrl-Left
Posts: 3
Joined: 26 Mar 2020, 16:57

Double Left -> Ctrl-Left – problem with the script

26 Mar 2020, 17:06

Hi all ~

1) I'd like to ease editing of texts for myself, so came up with the idea of replacing two hits of Left arrow with a Ctril-Left. This is what I got (kindly see below). I got it working for two presses of Left, but strangely when I press Left, then Right - (or any other special key for that matter), the reaction is the same like for the two Lefts. Can you please advise what seems to the problem here?

2) The script below works for two Lefts pressed even in a row regardless of the time period between them. Can you please advise how I could limit the time period (say, 0.1 sec)? So the script would only change two Lefts pressed within 0.1 sec one after each other, or otherwise just put in two plain Lefts in a row.

Many thanks in advance for you kind attention and help! Very much appreciated!

~Left::
;MsgBox, WeAreIn
Input, SingleKey, L1, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{CapsLock}{NumLock}{PrintScreen}{Pause}
if !(SingleKey = Left)
{
MsgBox, NotLeft
SendInput, %SingleKey%
Return
}
else
{
MsgBox, IsLeft
Send ^{Left}
}
User avatar
boiler
Posts: 3914
Joined: 21 Dec 2014, 02:44

Re: Double Left -> Ctrl-Left – problem with the script  Topic is solved

26 Mar 2020, 18:42

Try this. I found it can't distinguish < 0.1 sec but it works with < 0.2 sec.

Code: Select all

$Left::
	if (A_PriorHotkey = A_ThisHotkey) && (A_TimeSincePriorHotkey < 200)
		Send, ^{Left}
	else
		Send, {Left}
return
It can also be done in one line:

Code: Select all

$Left::Send, % (((A_PriorHotkey = A_ThisHotkey) && (A_TimeSincePriorHotkey < 200)) ? "^" : "") "{Left}"
Ctrl-Left
Posts: 3
Joined: 26 Mar 2020, 16:57

Re: Double Left -> Ctrl-Left – problem with the script

27 Mar 2020, 01:33

Many many thanks, sir ! Works like a charm !

Return to “Ask For Help”

Who is online

Users browsing this forum: akaza_dorian, Bing [Bot], NaNoMister, SashaChernykh, Scr1pter and 387 guests