c This keyboard provides a reasonably complete example of
c start-of-sentence detection, for use in testing #3621.
store(&VERSION) '10.0'
store(&NAME) 'start_of_sentence_3621'
store(&COPYRIGHT) '©'
store(&KEYBOARDVERSION) '1.0'
store(&TARGETS) 'any'
store(&VISUALKEYBOARD) 'start_of_sentence_3621.kvks'
store(&LAYOUTFILE) 'start_of_sentence_3621.keyman-touch-layout'

begin Unicode > use(main)
begin NewContext > use(NewContext)
begin PostKeystroke > use(PostKeystroke)

group(NewContext) readonly
    c Any time we get a new context, by mouse click, tap,
    c cursor movement, new document, etc, we'll try and
    c determine the best layer to use
    nomatch > use(nextLayer)

group(PostKeystroke) readonly

store(caps) 'A'..'Z'
store(digit) '0'..'9'

    c this is a heuristic that we can use until we support a CAPS layer (#3620):
    c if we find two+ characters in capitals, leave us in shift layer,
    c assuming the user hasn't just switched layer themselves. Once we have a
    c proper CAPS layer, we'll get rid of this.
    if(&newLayer = "") any(caps) any(caps) > context

    c stay on the numeric layer if we are there already
    if(&newLayer = "") if(&layer = 'numeric') any(digit) > context

    c no other changes, so detect sentence or layer change, as long
    c as the user hasn't attempted to change layer themselves
    if(&newLayer = "") > use(nextLayer)

group(nextLayer) readonly

    store(sentencePunctuation) '.?!'
    nul > layer('shift')
    c note that 'readonly' layers do not need to use 'context' unless there is
    c no other content on output of rule (empty output is illegal)
    any(sentencePunctuation) ' ' > layer('shift')
    any(sentencePunctuation) '  ' > layer('shift')
    nomatch > layer('default')

group(main) using keys

