Keyboard Support

Contact and Search Homepage

Header bottom

On this page



The if() statement allows a rule to be applied conditionally on the basis of the content of a variable store.


if(storeName comparison store2) ... > ...
if(storeName comparison constant) ... > ...


The variable store to test.
Either = or !=, for equal and not equal, respectively.


The if() statement allows any rule to be applied conditionally, depending on the content of store storeName, which can be defined either during keyboard configuration or dynamically by using a set() statement. The content of storeName 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 variable store (used in an if(), set(), save() or reset() statement) should not also be used to match context or key, or output in a rule. (Note: this advice has changed from previous versions of Keyman. The compiler will warn on this misuse.)


if(opt1 = '1') + any(letterGroup1) > index(outputGroup1,2)

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,3)

or separately (logical "OR"):

if(opt1 = '1') + any(letterGroup1) > index(outputGroup1,2) 
if(opt2 = '1') + any(letterGroup1) > index(outputGroup1,2)


The if() statement can be used in keyboards on the following platforms.

Support for Mac and Linux is incomplete as the options.htm form to set variable stores is not supported.

WindowsmacOSLinuxDesktop webMobile webiOSAndroid

Version history

The if() statement was introduced in Keyman 8.0.

Keyman 9.0: Added support for variable system stores.

Keyman for macOS 11.0.221 added support for if(), set(), save() and reset() for variable stores.

See also