Example #1
0
        void OnPhysicalKey(KeyEventArgs args, bool down)
        {
            // Emulator control keys
            switch (args.KeyCode)
            {
            case Keys.Pause: if (down)
                {
                    Running = !Running;
                }
                ; return;

            case Keys.Escape: if (down)
                {
                    UseLogicalKeyboardLayout = !UseLogicalKeyboardLayout;
                }
                ; return;
            }

            // KeyCode is the PHYSICAL key pressed so Keys.Q would be the first letter on the first row of letters.
            // For an AZERTY keyboard when the "A" key is pressed the KeyCode value is Keys.Q.
            if (KeyCodeMap.TryGetValue(args.KeyCode, out var keyCode))
            {
                spectrum.Keyboard.OnPhysicalKey(down, keyCode);

                // Windows is unable to detect when a shift key is released if the other shift key is still pressed
                // As a workaround if one is released, release them both
                if (!down && (keyCode == KeyCode.ShiftLeft || keyCode == KeyCode.ShiftRight))
                {
                    spectrum.Keyboard.OnPhysicalKeys(down: false, Key.CAPS, Key.SYMB);
                }
            }
        }
 public static KeyCodes GetKeyCode(Keys key)
 {
     return(KeyCodeMap.TryGetValue(key, out var keyCode) ? keyCode : 0);
 }