AutoHotKey script changes input language, how to avoid this?

醉酒当歌 提交于 2021-01-29 10:57:49

问题


; switch between virtual desktops (win10)
; supposed to be launched in initial desktop
flag := 0
LAlt & D::
if(flag = 0){
    send, {Control Down} {LWin Down} {Right} {Control Up} {LWin Up}
    flag := 1
    Return
}
else{
    send, {Control Down} {LWin Down} {Left} {Control Up} {LWin Up}
    flag := 0
    Return
}

when applied, there are chances to show the Language Bar and even change the input language. Any advice on this, please?


回答1:


While I can't say for sure why it opens the language bar, this article shows how to disable the built-in hotkeys for the language bar: https://winaero.com/blog/change-hotkeys-switch-keyboard-layout-windows-10/

There may be some minor issues with your code as well. It looks like there are spaces between your braces; the Send command will send those spaces. Of course, I wouldn't expect that this would cause the problems you're experiencing.

Here's a condensed version of your code that may possibly behave better:

<!d::
flag := !flag
If flag
    Send , ^#{right}
Else
    Send , ^#{left}
Return

Here's an even more condensed version using the ternary operator:

<!d::
sKeyName := ( flag := !flag ) ? "right" : "left"
Send , ^#{%sKeyName%}
Return

Here it is in one line:

<!d::Send , % "^#{" . (( flag := !flag ) ? "right" : "left" ) . "}"

I didn't know it was possible to put all that in one line, so I learned something today. :D



来源:https://stackoverflow.com/questions/54170938/autohotkey-script-changes-input-language-how-to-avoid-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!