AppleScript 随机浮动的回报 [英] AppleScript return on random float

查看:21
本文介绍了AppleScript 随机浮动的回报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 AppleScript 中创建代码,该代码将每 1-2 秒随机点击我的鼠标...我想要一个我正在玩的视频游戏,但不知道或能够告诉我机器人正在为我点击所以我需要它是随机的......不是每秒或每 2 秒一次,而是每 x 秒一次,其中 x 是一个在 1 到 2 秒之间不断变化的变量......这是到目前为止的代码,但它每 1 秒点击一次:

I'm trying to create code in AppleScript that will click my mouse randomly every 1-2 seconds... I want a video game I'm playing to not know or be able to tell that a robot is clicking for me so I need it to be RANDOM... not every second or every 2 seconds but every x seconds where x is a constantly changing variable in-between 1 and 2 seconds... Here is the code so far but it clicks every 1 second:

on idle
    tell application "System Events"
        key code 87
    end tell
    return 1
end idle

我认为将 return 1 更改为 return random number 1 to 2 会起作用

I thought changing the return 1 to return random number 1 to 2 would work

像这样:

on idle
    tell application "System Events"
        key code 87
    end tell
    set randomDelay to random number from 1 to 2
    return randomDelay
end idle

但是没有用/:

推荐答案

变成

random number from 1.0 to 2.0

如果你给整数作为随机数的界限,它只会选择随机整数.通过提供浮点文字,AppleScript 切换到提供范围内的随机浮点数.从 StandardAdditions 中 random number 的文档来看,这些限制似乎都包含在内,这对于浮点数来说很奇怪,但在您的情况下不是问题.

If you give integers as the bounds for the random numbers, it will just select random integers. By giving floating point literals, AppleScript switches to giving a random floating point number in the range. From the documentation of random number in the StandardAdditions, it seems that the limits are both inclusive, which is strange for floats but isn't a problem in your case.

这篇关于AppleScript 随机浮动的回报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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