if statement
if(%optName% = | != %storeName% | %stringValue%) %ruleContext% + %ruleKey% > %ruleOutput%
The if statement allows any rule to be applied conditionally, depending on the content of store optName, which can be defined either during keyboard configuration or dynamically by using a set statement. The content of store optName is tested to see whether it matches (or does not match) a string or the content of another store, and the following rule used or ignored accordingly.
A store being used for an option (in an if, set, save or reset statement) may also be used to match context or output in a rule, but may not be used to match keystrokes.
Example
if(opt1 = '1') + any(letterGroup1) > index(outputGroup1,1)
The rule to output a character from the outputGroup1 store according to a keystroke matching a character in store letterGroup1 will only be applied if the content of store opt1 is exactly equal to the string '1'.
Where two or more separate options are held in stores, the different options can be tested together (logical "AND"):
if(opt1 = '1') if(opt2 = '1') + any(letterGroup1) > index(outputGroup1,1)
or separately (logical "OR")
if(opt1 = '1') + any(letterGroup1) > index(outputGroup1,1) if(opt2 = '1') + any(letterGroup1) > index(outputGroup1,1)
Versions
The if keyword was introduced in Keyman 8.0.