AppleScript 随机浮动的回报

编程入门 行业动态 更新时间:2024-10-28 00:28:30
本文介绍了AppleScript 随机浮动的回报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 13:59:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AppleScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!