anonymous1184

JumpingJack.v2.ahk

Mar 30th, 2021 (edited)
14,342
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sleepTime := 3000
  2. keyDelay := 50
  3. pressDuration := 10
  4.  
  5. toggle := 0
  6. SetKeyDelay % keyDelay, % pressDuration
  7.  
  8. #MaxThreadsPerHotKey 2
  9. F1::
  10.     toggle ^= 1
  11.     while toggle
  12.     {
  13.         Send % "/" Format("{:U}", Number2Name(A_Index)) "{Enter}{Space}"
  14.         Sleep % sleepTime
  15.     }
  16. return
  17.  
  18. ;
  19. ; AutoHotkey: v1.1.11+
  20. ; Language:   English
  21. ; Platform:   Win7
  22. ; Author:     iPhilip
  23. ;
  24. ; Converts a number into the name of the number
  25. ;
  26. ; The function Number2Name(Number) converts an integer from 1 to 999,999,999,999 into the name of the number.
  27. ; For example, the number 264358 converts to "two hundred sixty-four thousand three hundred and fifty eight".
  28. ; See http://en.wikipedia.org/wiki/List_of_numbers#Cardinal_numbers for reference. Comma separators in the
  29. ; number are allowed, e.g. 264,358.
  30. ;
  31. ; The function sets ErrorLevel to one of the following values:
  32. ;
  33. ;    0 - If the conversion was successful
  34. ;    1 - If the number contains any non-digit characters other than commas ("123.4")
  35. ;    2 - If the number is larger than the maximum (10**12-1)
  36. ;
  37. ; ------------------------------------------------------------------------------------------
  38.  
  39. Number2Name(Number)
  40. {
  41.    static OnesArray := ["one","two","three","four","five","six","seven","eight","nine"]
  42.    static TeensArray := ["ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"]
  43.    static TensArray  := ["twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
  44.    static ThousandsArray := ["thousand","million","billion"]
  45.  
  46.    StringReplace, Number, Number, `,, , All          ; Remove any comma separators from the input string
  47.    ErrorLevel := 0                                   ; Initialize the error code to the default value
  48.    if Number is not digit                            ; If the string contains anything other than digits
  49.       ErrorLevel := 1                                ; Set the corresponding error code
  50.    else if (Number > 10**12-1)                       ; Otherwise, if the number is larger than the maximum ...
  51.       ErrorLevel := 2                                ; Set the corresponding error code
  52.    if ErrorLevel                                     ; If the error code is non-zero
  53.       Return                                         ; Return
  54.    String =                                          ; Initialize the output string
  55.    NumPeriods := Ceil(StrLen(Number)/3)              ; Calculate the number of periods in the number
  56.    Loop %NumPeriods%                                 ; Loop through for each period
  57.    {                                                 ; A period is a grouping of three digits, e.g. 46,322 has two periods
  58.       Multiplier := 10**(3*(NumPeriods-A_Index))     ; Calculate the multiplier corresponding to the current period
  59.       Period := Floor(Number/Multiplier)             ; Extract the current period
  60.       Hundreds := Floor(Period/100)                  ; Calculate the hundreds digit for the period
  61.       Tens := Floor((Period-Hundreds*100)/10)        ; Calculate the tens digit for the period
  62.       Ones := Period-Hundreds*100-Tens*10            ; Calculate the ones digit for the period
  63.       if Hundreds                                    ; If the period has a non-zero hundreds digit ...
  64.          String .= OnesArray[Hundreds] A_Space "hundred" A_Space   ; Append the name for the ones digit and the word "hundred" to the string, e.g. "two hundred"
  65.       if (Tens > 1)                                  ; If the tens digit is greater than one, e.g. twenty-two
  66.       {
  67.          if (NumPeriods = 1 AND Hundreds OR NumPeriods > 1 AND A_Index > 1)
  68.          ; If there are fewer than 3 digits and the number is > 99 or there are multiple periods and it's not the first period ...
  69.             String .= "and" A_Space                  ; Append an "and " to the string
  70.          String .= TensArray[Tens-1]                 ; Append the name for the tens digit to the string
  71.          if Ones                                     ; If the period has a non-zero ones digit, e.g. 37
  72.             String .=  "-" OnesArray[Ones] A_Space   ; Append a dash and the name of the ones digit to the string
  73.       }
  74.       else if Tens                                   ; Otherwise, if the tens digit is one, e.g. 214
  75.       {
  76.          if (NumPeriods = 1 AND Hundreds OR NumPeriods > 1 AND A_Index > 1)
  77.          ; If there are fewer than 3 digits and the number is > 99 or there are multiple periods and it's not the first period ...
  78.             String .= "and" A_Space                  ; Append an "and " to the string
  79.          String .= TeensArray[Period-Hundreds*100-9] A_Space   ; Append the name of the of the "teens" digit to the string
  80.       }
  81.       else if Ones                                   ; Otherwise, if the tens digit is zero and the ones digit is non-zero ...
  82.       {
  83.          if (NumPeriods = 1 AND Hundreds OR NumPeriods > 1 AND A_Index > 1)
  84.          ; If there are fewer than 3 digits and the number is > 99 or there are multiple periods and it's not the first period ...
  85.             String .= "and" A_Space                  ; Append an "and " to the string
  86.          String .= OnesArray[Ones] A_Space           ; Append the name of the ones digit to the string
  87.       }
  88.       if (Period AND A_Index < NumPeriods)           ; If the period is non-zero and it's not the last period
  89.          String .= ThousandsArray[NumPeriods-A_Index] A_Space   ; Append the name of the "thousands" digit to the string
  90.       Number -= Period*Multiplier                    ; Reduce the number by the current period
  91.    }
  92.    String = %String%                                 ; Trim the space at the end of the string
  93.    Return String                                     ; Return the value of the string
  94. }
Add Comment
Please, Sign In to add comment