Double press for language switching

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
reykjavi
Posts: 3
Joined: 19 Sep 2016, 14:51

Double press for language switching

Post by reykjavi » 06 Jun 2023, 14:42

Hey,

I'm not proud that I'm asking for help here, but I wasn't able to make it work by myself.

I'd like to change the way I'm switching the keyboard layout/input language, since the current approach is a bit inconvinient to me. I already proved to myself that setting the wanted language is better than switching the language, since I don't need to check the current language before start typing.
So, I want to test out two schemas:

1. Double LCtrl for one language and double RCtrl for another.
2. Single LCtrl press for one language, double LCtrl press for another.

Shouldn't be triggered if used in conjunction with other keys (in shortcuts).

Not asking for the Windows system routines that switch the language here, it seems a bit complex and won't be working over remote connections. It will be more than fine to use the standard shortcut Windows offers for language switching, Ctrl+1 and Ctrl+2.

I'd highly appreciate your help.
Thanks.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Double press for language switching

Post by mikeyww » 06 Jun 2023, 19:20

Welcome to this AutoHotkey forum!

An example is below.

Code: Select all

#Requires AutoHotkey v2.0

~Ctrl Up:: {
 If A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 400
  Send '^1'
}

reykjavi
Posts: 3
Joined: 19 Sep 2016, 14:51

Re: Double press for language switching

Post by reykjavi » 07 Jun 2023, 01:33

@mikeyww Your eagerness to help is beyond any expectation, almost 22 thousands posts for 9 years! Impressive. Thank you.

I was able to get one approarch working with your help:

Code: Select all

#Requires AutoHotkey v2.0

~LCtrl Up:: {
 If A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 400
  Send '^1'
}

~RCtrl Up:: {
 If A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 400
  Send '^2'
}
However, when I try to achieve another one, with just one LCtrl involved to set the language by pressing once or twice, I fail:

Code: Select all

#Requires AutoHotkey v2.0

~LCtrl Up:: {
 If A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 400
  {
  Send '^2'
  }
 Else
  {
  Send '^1'
  }
}
But to my understanding the logic behind this is clear: We process the single left control release and check if the previous hotkey was the same left control and the time passed is less than 400 ms. If it was, then we send Ctrl+2, otherwise (either or all of two conditions aren't true) we send Ctrl+1. I suspect though the fact we sending 'Ctrl' along with the '1' is interpreted as the second Ctrl pressed, which yields in... sending ^2 again :)
How can I avoid sending Ctrl in Send '^1' as a hotkey that should be processed?

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Double press for language switching

Post by mikeyww » 07 Jun 2023, 06:30

It appears that your goal is to have a hotkey distinguish a single press from a double press. Lots of scripts are already posted to do that. Here is one example.

reykjavi
Posts: 3
Joined: 19 Sep 2016, 14:51

Re: Double press for language switching

Post by reykjavi » 08 Jun 2023, 05:55

Thanks, will digest the knowledge from both the manual and this board more thouroughly, as I can't overcome the problem with Ctrl in Send that interfers with Hotkey.

Post Reply

Return to “Ask for Help (v2)”