Keyboard Support

Contact and Search

Keyman.com Homepage

Header bottom

Keyman.com

On this page

if()

Summary

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

Syntax

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

Parameters

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

Description

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.)

Example

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)

Platforms

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

WindowsmacOSDesktop webMobile webiOSAndroid

Version history

The if() statement was introduced in Keyman 8.0.

Keyman 9.0: Added support for variable system stores.

See also

Feedback

If you have any feedback or questions, just fill in this form to get in touch.