Unplanned
Last Updated: 29 Apr 2024 13:00 by Martin Ivanov
Martin Ivanov
Created on: 29 Apr 2024 13:00
Category: VirtualKeyboard
Type: Bug Report
0
VirtualKeyboard: CapsLock key toggles the secondary display text of non-letter keys

The CapsLock key should toggle only the letters. Currently, it behaves as Shift because it shows the secondary text of other keys as well (for example the number keys and their special characters). To reproduce this the ShowSecondaryText attribute of the corresponding key should be set to False.

To work this around, you can create a custom view model for the numeric keys that updates the DisplayText manually.

 

public class CustomKeyFactory : DefaultKeyFactory
{
    public override BaseKeyViewModel CreateKey(int virtualKey, KeyType keyType = KeyType.Normal, string displayText = null, double width = 1, double height = 1, int alternateVirtualKey = -1, string alternateText = null, bool showSecondaryText = false)
    {
        if (keyType == KeyType.Normal)
        {
            return new CustomRegularKeyViewModel(virtualKey, width, height, showSecondaryText, displayText);
        }
        return base.CreateKey(virtualKey, keyType, displayText, width, height, alternateVirtualKey, alternateText, showSecondaryText);
    }
}

public class CustomRegularKeyViewModel : RegularKeyViewModel
{
    public CustomRegularKeyViewModel(int virtualKey, double keyWidth, double keyHeight, bool showSecondaryText, string displayText = null) : base(virtualKey, keyWidth, keyHeight, showSecondaryText, displayText)
    {
    }

    public override void Update(IKeyUpdateContext context)
    {            
        base.Update(context);
        if (this.VirtualKey >= 48 && this.VirtualKey <= 57) // you may need to extend the if-statement to check for other keys as well
        {
            this.DisplayText = context.IsShiftActive ? this.ShiftText : this.LowerText;
        }
    }
}

 

0 comments