AHK脚本将保持按钮变成切换按钮 [英] AHK script to turn hold buttons into toggle buttons

查看:113
本文介绍了AHK脚本将保持按钮变成切换按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,当您按住Shift键时,大写会变成大写,而Capslock键会做相同的事情,但只是切换.

我如何转动按住Shift键之类的按住键的功能,就像像Capslock键那样的切换键?

我已经尝试过了:

   if toggle
        Send, {LShift down}
    else
        Send, {LShift up}

LShift::
    toggle := !toggle
    return

但是由于某些原因它不起作用. 我认为它将根据LShift按钮更改的切换值来抬起或按住LShift按钮.但这是行不通的,绝不是大写字母.

解决方案

对我而言,第一件事是您的If语句位于代码的Autoexec部分中,而不包含在将被调用或执行的内容之外.一次,因此只检查一次Toggle状态,您可以整天按下LShift并更改Toggle,但是从那里不会发生任何代码.

首先,我想将您的代码移至热键"部分.虽然这种半奏方式无法产生一致的结果,但是请随时尝试一下:

LShift::
    toggle := !toggle 
    if (toggle = true) ; added this for clarity and consitency
        Send, {LShift down}
    else
        Send, {LShift up}
    return

下面是我过去使用的一种解决方案,当我记得它时,它起作用的原因是SetTimer可被热键中断,因此无论Timer例程在何处工作,该热键都会中断它并设置切换./p>

解决方案:

SetTimer, Toggler, 100 

$LShift::toggle := !toggle

Toggler: 
    if (toggle = true)
        Send, {LShift down}
    else
        Send, {LShift up}
Return

For instance the Shift button makes things capitals when you have it held down whereas the Capslock button does the same thing but as a toggle.

How can I turn a hold button such as the shift button act like a toggle button like the capslock button?

I have tried this:

   if toggle
        Send, {LShift down}
    else
        Send, {LShift up}

LShift::
    toggle := !toggle
    return

But it does not work for some reason. I figure that it will lift up or hold down the LShift button depending on the value of toggle which is changed by the LShift button. But it doesn't work, it's never a capital letter.

解决方案

First thing that popped out to me is that your If Statement is in the Autoexec section of your code and not contained within anything that will be called or executed more than once, so it's only checking Toggle state once, you could hit LShift and change Toggle all day long but no code would happen from there.

First I thought to move your code to the Hotkey section. While this semi worked I wasn't able to produce consistent results, feel free to try yourself:

LShift::
    toggle := !toggle 
    if (toggle = true) ; added this for clarity and consitency
        Send, {LShift down}
    else
        Send, {LShift up}
    return

Below is a solution I've used in the past, when I remembered it, the reason this works is SetTimer is an interruptible by Hotkeys, so no matter where Timer routine is working the hotkey interrupts it and sets the toggle.

Solution:

SetTimer, Toggler, 100 

$LShift::toggle := !toggle

Toggler: 
    if (toggle = true)
        Send, {LShift down}
    else
        Send, {LShift up}
Return

这篇关于AHK脚本将保持按钮变成切换按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆