当发送循环时热键不起作用 [英] hotkeys does not work when send is in loop

查看:31
本文介绍了当发送循环时热键不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设代码如下:

<前>环形{如果启用发送,/}米::启用:= !启用返回

例如,我想切换将 / 发送到记事本.但是,如果我通过按键盘上的 M 运行此代码,则再次按 M 键不会禁用发送.
看起来循环中的 send 命令导致了这个问题,因为我已经尝试使用 msgbox 它不会禁用 m 键.
我怎样才能使这个代码工作?(SendInput 和 Play 也不起作用)

解决方案

这是因为您的循环阻塞了任何其他执行.除非该循环是您脚本中唯一的内容,否则您通常希望避免使用循环并使用 计时器 代替.

定时器 不会阻止进一步的执行,但更像是它们自己的线程.这是使用计时器的示例:

slashTimerActive := 0米::如果 (!slashTimerActive)设置定时器,发送斜线,100;每 100 毫秒调用一次 sub别的设置定时器、发送斜线、关闭slashTimerActive := !slashTimerActive ;翻转变量返回;子程序发送斜线:发送输入,/返回

Assume this code:

Loop
{
    if enabled
        Send, /
}

m::
    enabled := !enabled
Return

I want to toggle sending / to a Notepad for example. But if I run this code by pressing M on keyboard, then pressing the M key again does not disable sending.
Looks like the send command in the Loop cause this issue since Ive tried using msgbox which does not disable the m key.
How can I make this code to work? (SendInput and Play does not work too)

解决方案

It's because your loop is blocking any other execution. Unless that loop is the only thing in your script, you generally want to avoid using loops and use timers instead.

Timers don't block further execution but act more like their own thread. Here's an example using a timer:

slashTimerActive := 0

m::
    if (!slashTimerActive)
        SetTimer, SendSlash, 100 ; Call the sub every 100ms
    else
        SetTimer, SendSlash, Off

    slashTimerActive := !slashTimerActive ; Flip the variable
return

; Subroutine
SendSlash:
    SendInput, /
return

这篇关于当发送循环时热键不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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