【问题标题】:Need Help - Simple Random Number Generator using Auto Hot Key Script需要帮助 - 使用 Autohotkey 脚本的简单随机数生成器
【发布时间】:2014-12-21 06:55:08
【问题描述】:

我已阅读 Auto Hot Key 的文档,但对编写脚本很陌生。我不断收到错误。

我想要一个非常简单的脚本 - 所以当我使用热键 CTRL-ALT-N - 自动热键会创建一个随机数:

3 位 - 十进制 - 8 位

第一组的第一个数字在 1 到 4 之间。

其余的可以完全随机。

关闭我尝试编辑的示例脚本 - 但我做错了。如果有人可以提供帮助,将不胜感激!

输出应如下所示:314.99382028 第一个数字始终介于 1 和 4 之间,其余的随机数,十进制始终是第 4 个字符。

然后,它应该只是将数字粘贴到您当前在窗口中的任何位置 - 而不是弹出显示。

感谢任何可以快速查看并提供帮助的人。

火箭

^!n:: ;<-- change this if you want a diff hotkey
Chars1 = 1234
Chars2 = 1234567890
Chars3 = .
str =
clipboard =
UpperRange = 3 ;<-- use all 3 character strings
len = 12 ;<-- number of characters in the number

; generate a new number
loop, %len%
{ random,x,1,%UpperRange% ;<-- selects the Character string
random,y,1,26 ;<-- selects the character in the string
if (x = 12) ; if numeric there are only 10 digits
}
{ random,y,1,10
StringMid,z,Chars%x%,1 ;<-- grab the selected letter
str = %str%%z% ;<-- and add it to the number string
}
clipboard = %str% ;<-- put the completed string on the clipboard
Clipwait ;<-- wait for the clipboard to accept the string`

然后粘贴我的光标所在的位置 - 不知道该怎么做。

非常感谢您的帮助!

火箭

【问题讨论】:

    标签: random numbers generator autohotkey


    【解决方案1】:

    如果我理解正确,这应该可以完成工作:

    ^!n::
        SendInput, % "{LButton}" . RandomString(1,"1234") . RandomString(2) . "." . RandomString(8)
    Return
    
    RandomString(length,chars:="0123456789") {
        charsCount := StrLen(chars)
        Loop % length {
            Random, num, 1, % StrLen(chars)
            string .= SubStr(chars,num,1)
        }
        Return string
    }
    

    【讨论】:

      【解决方案2】:

      由于您的剪贴板上有答案,您可以简单地使用:

      Send, ^v
      

      这将粘贴插入符号所在的位置,而不是鼠标光标所在的位置,因此如果要粘贴鼠标光标所在的位置,只需添加 Click before...。

      Click
      Sleep, 30
      Send, ^v
      

      【讨论】:

        猜你喜欢
        • 2015-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-24
        • 2018-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多