manual:Calculations
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| manual:Calculations [2018/06/30 07:26] – [Operators] peternlewis | manual:Calculations [2025/02/26 02:04] (current) – [Operators] peternlewis | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ===== Overview ===== | ===== Overview ===== | ||
| - | Keyboard Maestro supports calculations in almost any numeric [[/ | + | Keyboard Maestro supports calculations in almost any numeric [[/ |
| ===== Examples ===== | ===== Examples ===== | ||
| Line 23: | Line 23: | ||
| Operators based on precedence from lowest to highest are: | Operators based on precedence from lowest to highest are: | ||
| - | | Array Separator (`,`) | Allows a text Variable, which has comma separated values, to work somewhat like an Array.\\ Assume `MyKMVariable` contains "value1,value2,value3".\\ Then `MyKMVariable[2]` returns "value2". | | + | | Array Separator (`,`) | Allows a text Variable, which has comma separated values, to work somewhat like an Array.\\ Assume `MyKMVariable` contains "12,34,56", then `MyKMVariable[2]` returns "34". | |
| | Ternary Operator (`?`) | a=b ? 3 : 4 | | | Ternary Operator (`?`) | a=b ? 3 : 4 | | ||
| - | | Bitwise OR (`|`), Bitwise AND (`&`) and Bitwise XOR | operators | | + | | Bitwise OR (`|`), Bitwise AND (`&`) and Bitwise XOR | bitwise |
| - | | Comparison Operators (`<, ≤, =, >, ≥, ≠`) | compare for (in)equality and return 0 or 1 | | + | | Comparison Operators (`<, ≤, =, >, ≥, ≠`) | compare for (in)equality and return 0 or 1. | |
| - | | Shift Operators (`≪, ≫`) | shift a number left or right | | + | | Shift Operators (`≪, ≫`) | shift a number left or right. | |
| - | | Arithmetic Operators\\ • Add (`+`)\\ • Subtract (`-`)\\ • Multiply (`*`)\\ • Divide (`/`) | A mathematical | + | | Arithmetic |
| - | | [Modulo](https:// | + | | Arithmetic Multiplication Operators |
| - | | Power Operator (`^`) | exponentiation | | + | | [Modulo](https:// |
| - | | Unary Prefix Operators (`√`, `-`, `( )` ) | square root, negation, sub-expressions | | + | | Integer division (`i DIV n`) | The integer |
| - | | [[: | + | | Power Operator (`^`) | exponentiation. | |
| - | | Numbers and Variables or Array Accesses (5, | + | | Unary Prefix Operators (`√`, `-`, `( )` ) | square root, negation, sub-expressions. | |
| - | | Unary Postfix Operators (`!,%,°`)) | factorial, percent, degrees | | + | | [[: |
| + | | Numbers and Variables or Array Accesses (5, | ||
| + | | Unary Postfix Operators (`!,%,°`)) | factorial, percent, degrees. | | ||
| - | Numbers are in decimal by default, but may use base 16 if they start with `$` or `0x` (eg $5A or 0x5A), or may start with a specific base followed by a `#` (eg 8#007). | + | Numbers are in decimal by default, but may use base 16 if they start with `$` or `0x` (eg $5A or 0x5A), or may start with a specific base followed by a `#` (eg 8#007). Numbers may include underscores, |
| [[Variables|Variables]] can be used if they contain numeric expressions, | [[Variables|Variables]] can be used if they contain numeric expressions, | ||
| - | You can use either `=` or `==` (v8+) for testing for equality. | + | You can use either `=` or `==` for testing for equality. |
| Operators and functions must be in uppercase to minimize conflict with variables. | Operators and functions must be in uppercase to minimize conflict with variables. | ||
| + | |||
| ===== Functions ===== | ===== Functions ===== | ||
| The available functions are listed on the [[/ | The available functions are listed on the [[/ | ||
| - | You can insert a function by name by choosing [[Menus#Insert_Function_by_Name|Insert Function | + | You can insert a function by name by choosing |
| ===== Variables ===== | ===== Variables ===== | ||
| - | In numeric calculation fields, Variable Names are used without the `%` that are used in text token fields. | + | In numeric calculation fields, Variable Names are used without the `%` that are used in text token fields. |
| - | + | ||
| - | ===== Screen Coordinates ===== | + | |
| - | + | ||
| - | Keyboard Maestro refers to screen coordinates as two or four comma separated numbers in the text of a Keyboard Maestro Variable (which is always a string). | + | |
| - | * Screen object points, like the left,top position of a window, have two values, like 12,34 | + | |
| - | * Screen object rectangles, like the frame of a window, have four values 12,34,56,78 (with a fifth value for fuzz in some instances). | + | |
| - | * You can reference these values by position in the string, as it the Variable were an array: | + | |
| - | * For example: | + | |
| - | if the Variable `myWindow` is " | + | |
| - | then all of these forms of reference will provide a value of 34 in a Calculation field: | + | |
| - | * myWindow[2] | + | |
| - | * myWindow.y | + | |
| - | * myWindow.Top | + | |
| ===== Variable Array Access ===== | ===== Variable Array Access ===== | ||
| Line 74: | Line 64: | ||
| Indices are 1-based, so MyVar[1] is the first element. | Indices are 1-based, so MyVar[1] is the first element. | ||
| - | ===== Variable | + | ===== Screen Coordinates and Dot Notation ===== |
| + | |||
| + | Keyboard Maestro refers to screen coordinates as two or four comma separated numbers in the text of a Keyboard Maestro Variable (which is always a string). | ||
| + | |||
| + | Screen object points, like the left,top position of a window, have two values, like 12,34. | ||
| + | |||
| + | Screen object rectangles, like the frame of a window, have four values 12,34,56,78 (with a fifth value for fuzz in some instances). | ||
| In a Calculation field you can reference the numbers in a Keyboard Maestro Variable (which is always a string) using dot notation: | In a Calculation field you can reference the numbers in a Keyboard Maestro Variable (which is always a string) using dot notation: | ||
| Line 89: | Line 85: | ||
| | Variable.MidX | the horizontal middle of a rectangle | | | Variable.MidX | the horizontal middle of a rectangle | | ||
| | Variable.MidY | the vertical middle of a rectangle | | | Variable.MidY | the vertical middle of a rectangle | | ||
| + | |||
| + | For example if the Variable `myWindow` is " | ||
| + | * myWindow[2] | ||
| + | * myWindow.y | ||
| + | * myWindow.Top | ||
| The Variable Name and Dot reference are case insensitive. | The Variable Name and Dot reference are case insensitive. | ||
| + | |||
| ===== Text Fields ===== | ===== Text Fields ===== | ||
| Line 99: | Line 101: | ||
| However in a text field, since any text is allowed, you must use percent encoded tokens to indicate where more processing is required. | However in a text field, since any text is allowed, you must use percent encoded tokens to indicate where more processing is required. | ||
| - | The result is %Calculate%3 * Count + 7%. | + | The result is %Calculate% 3 * Count + 7 %. |
| - | ===== Examples of Variable | + | ===== Examples of Variable |
| - | ** Macro Actions**\\ | + | === Macro Actions |
| - | {{: | + | |
| - | **Example Results**\\ | + | {{ window-frame-example-actions.png?nolink& |
| - | {{:manual:window-frame-example-results-km-7.3.png? | + | |
| - | Some example | + | === Example Results === |
| + | |||
| + | {{ window-frame-example-results.png? | ||
| + | |||
| + | ===== Example Expressions ===== | ||
| < | < | ||
| Amount in Dollars * 100 | Amount in Dollars * 100 | ||
| MJD() > 55928 | MJD() > 55928 | ||
| - | NOW() > TIME(2012, | + | NOW() > TIME(2023, |
| - | DOW(TIME(2012,4,4)) = 4 | + | DOW(TIME(2023,4,4)) = 4 |
| Radius*SIN(20°), | Radius*SIN(20°), | ||
| Window Frame[1]+Window Frame[3]/ | Window Frame[1]+Window Frame[3]/ | ||
| Line 122: | Line 126: | ||
| </ | </ | ||
| - | --- | ||
| - | |||
| - | **KeyWords: | ||
manual/Calculations.1530343580.txt.gz · Last modified: by peternlewis
