AppleScript return on random float

限于喜欢 提交于 2019-12-12 03:43:15

问题


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

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

Something like this:

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

but it didn't work /:


回答1:


Make it into

random number from 1.0 to 2.0

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.



来源:https://stackoverflow.com/questions/10057289/applescript-return-on-random-float

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!