英文:
What is the difference between these two examples of code?
问题
以下是您要翻译的内容:
我已经在过去的一年中在各处都在使用While GetKeyState("<some key>", "p")
,而没有真正思考实际发生了什么。
space::
While GetKeyState("space", "p")
{
MyVar++
Tooltip, % "MyVarIs: " MyVar
Sleep 500
}
上面的Tooltip
命令是否只触发每半秒一次?
如果是这样,那么以下代码是如何工作的?因为没有Sleep 500
:
space::
if GetKeyState("space", "p")
{
MyVar++
Tooltip, % "MyVarIs: " MyVar
}
我认为它应该只触发一次。要再次触发,我必须释放并再次按下Space
键,但事实并非如此。Tooltip命令会持续触发,就像在While示例中一样。
感谢任何帮助。
英文:
I have been using While GetKeyState("<some key>", "p")
everywhere for best part of a year without really thinking about what is actually happening.
space::
While GetKeyState("space", "p")
{
MyVar++
Tooltip, % "MyVarIs: " MyVar
Sleep 500
}
Is the above Tooltip
command, essentially only triggering every half a second?
if so then how is the following working? Since Sleep 500
is absent:
space::
if GetKeyState("space", "p")
{
MyVar++
Tooltip, % "MyVarIs: " MyVar
}
I am thinking it should only fire once. To fire again I have to release and press Space
again, but that is not the case. The Tooltip command continuously fires just like in the While example.
Thanks for any help.
答案1
得分: 1
第一个提示命令每半秒触发一次,因为有 Sleep 500
。
第二个命令在按住键时持续触发:
space::
; if GetKeyState("space", "p") ; 多余的
; {
MyVar++
Tooltip, % "MyVarIs: " MyVar
; }
return
要使其仅在释放键时触发一次,请使用 Up 变体:
space Up::
MyVar++
Tooltip, % "MyVarIs: " MyVar
return
或者使用 KeyWait 命令。
英文:
The first Tooltip command is triggering every half a second because of Sleep 500
.
The second is continuously triggering if the key is holding down:
space::
; if GetKeyState("space", "p") ; redundant
; {
MyVar++
Tooltip, % "MyVarIs: " MyVar
; }
return
To make it fire only once (by releasing), use the Up variant:
space Up::
MyVar++
Tooltip, % "MyVarIs: " MyVar
return
or the KeyWait command.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论