Keyboard Support

Contact and Search Homepage

Header bottom

Other versions
Version 17.0 (current version)Version 16.0Version 15.0Version 14.0Version 13.0Version 12.0Version 11.0Version 10.0

On this page

stateMatch (KSM)


State-key matching: Returns true if the event matches the rule's state-key requirements.


keyman.interface.stateMatch(e, shiftCode);


KeymanWeb.KSM(e, shiftCode); // Shorthand


Type: Object
A keystroke-related event object to match.
Type: number
The state-key bitflags the event should match.

Return Value

true if the keystroke matches the desired states, otherwise false.


As of KeymanWeb 10.0, KeymanWeb now supports keyboard rules conditioned upon 'state keys' like Caps Lock if specified by keyboard developers. The stateMatch function examines the bit-flags to determine the state keys being tested and compares the keyboard event against them as appropriate. As such, it is designed to be a condition check alongside keyman.interface.keyMatch() and keyman.interface.contextMatch().

For comparison with Developer 'rules' from keyboard source code, in the rule

+ [CAPS K_A]  > 'BIG A'
+ [NCAPS K_A] > 'small a'

a keyboard would check which rule the triggering keystroke ("a") matches by using

keyman.interface.stateMatch(e, 0x100)

from within a raised keystroke event with object e, which checks that the keystroke represented by e has an activated Caps Lock state as represented by the code 0x0100. The NCAPS rule would instead compare against 0x0200.

As keyman.interface.stateMatch() receives an event object as one of its parameters, it does not need a direct link to the element receiving input.

See also