Skip to content

An on-screen keyboard that renders a full or tenkeyless layout, reacts to pointer input, mirrors physical key presses, and follows the active system keyboard layout.

xml
<dev:MagicKeyboard Skin="System"
                   Layout="Ansi"
                   FormFactor="Full"
                   Platform="Windows"
                   IsPreviewVisible="True"
                   KeyEvent="Keyboard_KeyEvent" />
csharp
private void Keyboard_KeyEvent(MagicKeyboard sender, MagicKeyEventArgs e)
{
    Debug.WriteLine($"{e.Code} {(e.IsDown ? "down" : "up")} via {e.Source}");
}

Properties ​

Appearance ​

PropertyTypeDefaultDescription
SkinMagicKeyboardSkinSilverColor skin. System picks LightSkin or DarkSkin from the current theme.
LightSkinMagicKeyboardSkinSilverSkin used in light theme when Skin is System.
DarkSkinMagicKeyboardSkinMidnightSkin used in dark theme when Skin is System.
LayoutMagicKeyboardLayoutAnsiAnsi or Iso key arrangement.
FormFactorMagicKeyboardFormFactorFullFull or Tenkeyless.
PlatformMagicKeyboardPlatformWindowsWindows or Mac legends and bottom row.
LetterCaseMagicKeyboardKeyCaseLowerCase of letter legends when Shift and Caps Lock are off.
IsPreviewVisibleboolfalseShows a floating preview of the last pressed key.

Input ​

PropertyTypeDefaultDescription
ModifierModeMagicKeyboardKeyModifierModeStickyHold keeps a modifier down while pressed, Sticky releases it after the next key, Toggle stays latched until pressed again.
LinkModifierKeysbooltrueShows left and right Shift, Control and Alt as pressed together.
IsPhysicalKeyboardEnabledbooltrueMirrors physical key presses on the control.
IsAlwaysActiveboolfalseKeeps listening to the physical keyboard when the control is scrolled out of view.
FollowSystemKeyboardLayoutbooltrueReads key legends from the active Windows keyboard layout and updates when it changes.
SyncCapsLockbooltrueSyncs the Caps Lock LED and letter case with the system state.
SyncNumLockbooltrueSyncs the Num Lock LED with the system state.

Sound ​

PropertyTypeDefaultDescription
IsSoundEnabledboolfalsePlays key sounds.
KeyDownSoundUristring""Absolute URI of the key down sound.
KeyUpSoundUristring""Absolute URI of the key up sound.
SoundVolumedouble0.5Volume from 0 to 1.

Events ​

EventArgumentsDescription
KeyEventMagicKeyEventArgsRaised when a key is pressed or released.

MagicKeyEventArgs exposes Code (a physical key code such as KeyA or ShiftLeft), Label, IsDown, Source (Pointer or Physical) and Modifiers (MagicKeyboardKeyModifiers).

Skins ​

SkinDescription
SilverLight aluminum keys.
SpaceGrayDark keys on a gray chassis.
MidnightNear-black keys on a dark blue chassis.
CustomColors come from the MagicKeyboardCustom* resources and follow the app theme.
SystemUses LightSkin or DarkSkin by theme, and Custom in high contrast.

Customizing colors ​

Every skin is a set of Color resources named MagicKeyboard{Skin}{Part}, for example MagicKeyboardSilverFaceTop. Override any of them in App.xaml, a page, or any parent element. SolidColorBrush values are accepted too.

PartDescription
ChassisTop, ChassisBottomGradient of the keyboard body.
ChassisStrokeBody outline.
FaceTop, FaceBottomGradient of a key face.
PressTop, PressBottomKey face gradient while pressed.
EdgeKey side and bottom edge.
LegendPrimary legend color.
DimSecondary legend color.
LedActiveCaps Lock and Num Lock LED when on.

Custom is defined per theme, so it can be overridden in theme dictionaries:

xml
<ResourceDictionary.ThemeDictionaries>
    <ResourceDictionary x:Key="Light">
        <Color x:Key="MagicKeyboardCustomFaceTop">#FFFFFF</Color>
        <Color x:Key="MagicKeyboardCustomLegend">#1B1B1B</Color>
    </ResourceDictionary>
    <ResourceDictionary x:Key="Dark">
        <Color x:Key="MagicKeyboardCustomFaceTop">#2B2B2B</Color>
        <Color x:Key="MagicKeyboardCustomLegend">#FFFFFF</Color>
    </ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
xml
<dev:MagicKeyboard Skin="System" LightSkin="Silver" DarkSkin="Custom" />

The preview popup uses MagicKeyboardPreviewBackground, MagicKeyboardPreviewBorderBrush and MagicKeyboardPreviewForeground.

NOTE

  • Key legends follow the active keyboard layout only for character keys; function and modifier keys keep their fixed labels.
  • Physical keys are captured at the window root, so the keyboard reflects typing anywhere in the window while it is loaded and visible.
  • Pointer input and physical input raise the same KeyEvent; use Source to tell them apart.

MagicKeyboard

Demo ​

you can run demo and see this feature.

Released under the MIT License.