Change input language with CTRL only

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dhtj
Posts: 5
Joined: 22 Sep 2017, 18:13

Change input language with CTRL only

22 Sep 2017, 18:30

Hi guys,
I'm using windows 8.1 and I write in two languages often so I have to switch the input language (layout) using the default windows combination Ctrl + Shift.

I already broke one pair of ctrl and shift, and I have a new keyboard now so I want to keep it.

So can you help me with a script which is going to change the languages by only pressing CTRL, but still keep it's functionality for other ctrl combinations like copy and paste.

Thanks!
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Change input language with CTRL only

22 Sep 2017, 18:43

Hi, dhtj,
Try this:

Code: Select all

~Ctrl Up::
   if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  {
      ControlGetFocus, FocusedControl, A
      PostMessage, WM_INPUTLANGCHANGEREQUEST := 0x50, INPUTLANGCHANGE_FORWARD := 2,, % FocusedControl, A
   }
   Return
Last edited by teadrinker on 22 Sep 2017, 19:58, edited 1 time in total.
dhtj
Posts: 5
Joined: 22 Sep 2017, 18:13

Re: Change input language with CTRL only

22 Sep 2017, 19:01

Thank you for the fast response.

It works but it's has a bit of a lag.
When I press ctrl, the language indicator at the taskbar starts flashing and after 1-2 seconds the change is done.
And if I press any other key during these 1-2 seconds, the change is interrupted.

And if i press it more than 3 times it happens this:
hotkeys.jpg
hotkeys.jpg (27.65 KiB) Viewed 2679 times
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Change input language with CTRL only

22 Sep 2017, 19:16

Uh-uh... This should not happen, tested on two computers with Windows 7 and 10. Something is wrong with your keyboard, maybe? Hotkey "Ctrl Up" should not work until it is released.
dhtj
Posts: 5
Joined: 22 Sep 2017, 18:13

Re: Change input language with CTRL only

22 Sep 2017, 19:33

I just took the keyboard out of the box, so i think its not the problem.
Also all CTRL combinations are working fine.

This is the log after ONE pressing and releasing the ctrl.
I'm not holding the button, just quick press and release.

Code: Select all

Script lines most recently executed (oldest first).  Press [F5] to refresh.  The seconds elapsed between a line and the one after it is in parentheses to the right (if not 0).  The bottommost line's elapsed time is the number of seconds since it executed.

---- C:\Program Files\AutoHotkey\hotkeys.ahk
003: SendMode,Input
004: SetWorkingDir,%A_ScriptDir%
006: Return (15.17)
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return (0.02)
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return (0.01)
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return (0.02)
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return (0.02)
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return (0.01)
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
011: ControlGetFocus,FocusedControl
012: PostMessage,WM_INPUTLANGCHANGEREQUEST := 0x50,INPUTLANGCHANGE_FORWARD := 2,,FocusedControl,A
013: }
014: Return
010: if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  
014: Return (1.61)

Press [F5] to refresh.
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Change input language with CTRL only

22 Sep 2017, 19:48

Do you run my code separately, or adding it to your script with other hotkeys?
Try one more version:

Code: Select all

~LCtrl Up::
~RCtrl Up::
   if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  {
      ControlGetFocus, FocusedControl, A
      PostMessage, WM_INPUTLANGCHANGEREQUEST := 0x50, INPUTLANGCHANGE_FORWARD := 2,, % FocusedControl, A
   }
   Return
Do any keyboard applications work in the same time?
Last edited by teadrinker on 22 Sep 2017, 20:03, edited 2 times in total.
dhtj
Posts: 5
Joined: 22 Sep 2017, 18:13

Re: Change input language with CTRL only

22 Sep 2017, 20:05

No other keyboard applications and scripts are runing.
I'm running your code only.

The second version works just like the first one. :(

Can we try different logic like:
"when ctrl is released :: act like ctrl+shift"
or
"when ctrl is released :: act like win+space"

I don't know how to write it properly though :D
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Change input language with CTRL only

22 Sep 2017, 20:10

Code: Select all

$~Ctrl Up:: SendInput, {Ctrl Down}{Shift}{Ctrl Up}
dhtj
Posts: 5
Joined: 22 Sep 2017, 18:13

Re: Change input language with CTRL only

22 Sep 2017, 20:25

Thanks!
This is working now:

Code: Select all

~Ctrl Up::
   if (A_PriorKey = "RControl" || A_PriorKey = "LControl")  {
      Send, {Ctrl down}{Shift down}{Shift up}{Ctrl up}{Ctrl up}
   }
   Return
china6k
Posts: 1
Joined: 25 Apr 2023, 07:01

Re: Change input language with CTRL only

25 Apr 2023, 07:04

For AHK v2, the working code is:

Code: Select all

Ctrl:: Send "{Ctrl down}{Shift down}{Shift up}{Ctrl up}"
Note the "Ctrl" hotkey is used without "Up" modifier as it is by activated on release by design

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hiahkforum, NullRefEx, ShatterCoder and 94 guests