Ejemplo n.º 1
0
        /// <summary>
        /// Checks whether a certain <see cref="Scancode"/> is down. Not to be confused with <see cref="Scene.KeyPressed(KeyConstant, Scancode, bool)"/> or <see cref="Scene.KeyReleased(KeyConstant, Scancode)"/>.
        /// <para>Unlike regular KeyConstants, Scancodes are keyboard layout-independent. The scancode "w" is used if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.</para>
        /// </summary>
        /// <param name="scancode"></param>
        /// <returns></returns>
        public static bool IsScancodeDown(Scancode scancode)
        {
            bool out_result = false;

            Love2dDll.wrap_love_dll_keyboard_isScancodeDown((int)scancode, out out_result);
            return(out_result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>Gets the key corresponding to the given hardware scancode.</para>
        /// <para>Unlike <see cref="KeyConstant"/>, <see cref="Scancode"/> are keyboard layout-independent. For example the scancode "w" will be generated if the key in the same place as the "w" key on an American keyboard is pressed, no matter what the key is labelled or what the user's operating system settings are.</para>
        /// <para><see cref="Scancode"/> are useful for creating default controls that have the same physical locations on on all systems.</para>
        /// </summary>
        /// <param name="scancode">The scancode to get the key from.</param>
        /// <returns>The key corresponding to the given <see cref="Scancode"/> , or "unknown" if the <see cref="Scancode"/> doesn't map to a KeyConstant on the current system.</returns>
        public static KeyConstant GetKeyFromScancode(Scancode scancode)
        {
            int out_key_type = 0;

            Love2dDll.wrap_love_dll_keyboard_getKeyFromScancode((int)scancode, out out_key_type);
            return((KeyConstant)out_key_type);
        }
Ejemplo n.º 3
0
        public void ShouldConvertScancodeToKeycode(Scancode scancode, Keycode expected)
        {
            var actual = scancode.ToKeycode();

            actual.Should().NotBe(Keycode.UNKNOWN);
            actual.Should().Be(expected);
        }
Ejemplo n.º 4
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
     if (key == KeyConstant.F)
     {
         Window.SetFullscreen(!Window.GetFullscreen());
     }
 }
Ejemplo n.º 5
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
     if (Keyboard.IsPressed(KeyConstant.C) && (Keyboard.IsDown(KeyConstant.LCtrl) || Keyboard.IsDown(KeyConstant.RCtrl)))
     {
         Special.SetClipboardText(errorMsg);
     }
 }
Ejemplo n.º 6
0
 public override void KeyReleased(KeyConstant key, Scancode scancode)
 {
     if (key == KeyConstant.Escape)
     {
         Event.Quit();
     }
 }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        public override Boolean IsButtonReleased(Scancode button)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            var scancode = (int)button;

            return(states[scancode].Released);
        }
Ejemplo n.º 8
0
            public void KeyReleased(KeyConstant key, Scancode scancode)
            {
                EventData ed = new EventData(EventType.KeyReleased);

                ed.key      = key;
                ed.scancode = scancode;
                list.AddLast(ed);
            }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        public override Boolean IsButtonPressed(Scancode button, Boolean ignoreRepeats = true)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            var scancode = (int)button;

            return(states[scancode].Pressed || (!ignoreRepeats && states[scancode].Repeated));
        }
Ejemplo n.º 10
0
            public void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
            {
                EventData ed = new EventData(EventType.KeyPressed);

                ed.key      = key;
                ed.scancode = scancode;
                ed.flag     = isRepeat;
                list.AddLast(ed);
            }
Ejemplo n.º 11
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
     if (key == KeyConstant.N)
     {
         currentTest = LoadTests();
         currentTest.LoadWorld();
         currentTest.Load();
         currentTest.ResetTranslation();
     }
 }
Ejemplo n.º 12
0
        static Key TranslateKey(Scancode scan)
        {
            Key result = Key.Unknown;

            if (map.ContainsKey(scan))
            {
                result = map[scan];
            }
            return(result);
        }
Ejemplo n.º 13
0
        public void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
        {
            switch (scancode)
            {
            case Scancode.Number1:
                CurrentGunIndex = 0;
                break;

            case Scancode.Number2:
                CurrentGunIndex = 1;
                break;
            }
        }
Ejemplo n.º 14
0
        public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
        {
            base.KeyPressed(key, scancode, isRepeat);

            if (key == KeyConstant.Right)
            {
                Zoom += 1;
            }
            if (key == KeyConstant.Left)
            {
                Zoom = Math.Max(Zoom - 1, 1);
            }
        }
Ejemplo n.º 15
0
 public EventData(EventType t)
 {
     type          = t;
     key           = KeyConstant.Unknown;
     scancode      = Scancode.Unknow;
     joystick      = null;
     direction     = JoystickHat.Centered;
     gamepadButton = GamepadButton.A;
     gamepadAxis   = GamepadAxis.LeftX;
     text          = null;
     flag          = false;
     fx            = 0;
     fy            = 0;
     fz            = 0;
     fw            = 0;
     fp            = 0;
     idx           = 0;
     idy           = 0;
     lid           = 0;
 }
Ejemplo n.º 16
0
        public override void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
        {
            base.KeyPressed(key, scancode, isRepeat);

            switch (key)
            {
            case KeyConstant.Right:
                Zoom += 1;
                break;

            case KeyConstant.Left:
                Zoom = Math.Max(Zoom - 1, 1);
                break;

            case KeyConstant.R:
                Zoom      = 8;
                Intensity = 2;
                break;
            }
        }
Ejemplo n.º 17
0
        /// <inheritdoc/>
        public void SpoofKeyUp(Scancode scancode, Key key, Boolean ctrl, Boolean alt, Boolean shift)
        {
            var data = Ultraviolet.Messages.CreateMessageData <SDL2EventMessageData>();

            data.Event = new SDL_Event()
            {
                key = new SDL_KeyboardEvent()
                {
                    type     = (uint)SDL_KEYUP,
                    windowID = (uint)Ultraviolet.GetPlatform().Windows.GetPrimary().ID,
                    keysym   = new SDL_Keysym()
                    {
                        keycode  = (SDL_Keycode)key,
                        scancode = (SDL_Scancode)scancode,
                        mod      =
                            (ctrl ? KMOD_CTRL : KMOD_NONE) |
                            (alt ? KMOD_ALT : KMOD_NONE) |
                            (shift ? KMOD_SHIFT : KMOD_NONE),
                    },
                }
            };
            Ultraviolet.Messages.Publish(SDL2UltravioletMessages.SDLEvent, data);
        }
Ejemplo n.º 18
0
 internal static extern IntPtr Input_GetScancodeName(IntPtr handle, Scancode scancode);
Ejemplo n.º 19
0
 /// <summary>
 /// Triggered when a keyboard key is released.
 /// </summary>
 /// <param name="key">Character of the pressed key.</param>
 /// <param name="scancode">The scancode representing the pressed key.</param>
 public virtual void KeyReleased(KeyConstant key, Scancode scancode)
 {
 }
Ejemplo n.º 20
0
        private static Key TranslateKey(Keycode key)
        {
            Scancode scan = SDL.GetScancodeFromKey(key);

            return(TranslateKey(scan));
        }
Ejemplo n.º 21
0
 private static Key TranslateKey(Scancode scan)
 {
     return(Sdl2KeyMap.GetKey(scan));
 }
Ejemplo n.º 22
0
		extern public static string GetScancodeName(Scancode scancode);
Ejemplo n.º 23
0
 /// <summary>
 /// Check if a key has been pressed on this frame by scancode.
 /// </summary>
 public bool GetScancodePress(Scancode scancode)
 {
     Runtime.ValidateRefCounted(this);
     return(Input_GetScancodePress(handle, scancode));
 }
Ejemplo n.º 24
0
            internal static Keys MapKey(KeyCode input, Scancode scancode)
            {
                // Resources: http://kbdlayout.info/kbdusx/overview+virtualkeys
                //            https://wiki.libsdl.org/SDL_Keycode
                //            http://kbdedit.com/manual/low_level_vk_list.html
                switch (input)
                {
                case KeyCode.KUnknown: return(Keys.None);

                case KeyCode.KCancel: return(Keys.Cancel);

                case KeyCode.KKPBackspace:
                case KeyCode.KBackspace: return(Keys.Back);

                case KeyCode.KTab:
                case KeyCode.KKPTab: return(Keys.Tab);

                //            KeyCode.KUnknown: return Keys.LineFeed;
                case KeyCode.KClear:
                case KeyCode.KClearagain:
                case KeyCode.KKPClear:
                case KeyCode.KKPClearentry: return(Keys.Clear);

                case KeyCode.KReturn:
                case KeyCode.KReturn2: return(Keys.Return);

                case KeyCode.KPause: return(Keys.Pause);

                //            KeyCode.KCapslock: return Keys.Capital; // Capital is the same as CapsLock
                case KeyCode.KCapslock: return(Keys.CapsLock);

                //            KeyCode.KUnknown: return Keys.HangulMode;
                //            KeyCode.KUnknown: return Keys.KanaMode;
                //            KeyCode.KUnknown: return Keys.JunjaMode;
                //            KeyCode.KUnknown: return Keys.FinalMode;
                //            KeyCode.KUnknown: return Keys.HanjaMode;
                //            KeyCode.KUnknown: return Keys.KanjiMode;
                case KeyCode.KEscape: return(Keys.Escape);

                //            KeyCode.KUnknown: return Keys.ImeConvert;
                //            KeyCode.KUnknown: return Keys.ImeNonConvert;
                //            KeyCode.KUnknown: return Keys.ImeAccept;
                //            KeyCode.KUnknown: return Keys.ImeModeChange;
                case KeyCode.KSpace:
                case KeyCode.KKPSpace: return(Keys.Space);

                case KeyCode.KPageup: return(Keys.PageUp);

                case KeyCode.KPrior: return(Keys.Prior);

                //            KeyCode.KPagedown: return Keys.Next; // Next is the same as PageDown
                case KeyCode.KPagedown: return(Keys.PageDown);

                case KeyCode.KEnd: return(Keys.End);

                case KeyCode.KHome: return(Keys.Home);

                case KeyCode.KLeft: return(Keys.Left);

                case KeyCode.KUp: return(Keys.Up);

                case KeyCode.KRight: return(Keys.Right);

                case KeyCode.KDown: return(Keys.Down);

                case KeyCode.KSelect: return(Keys.Select);

                //            KeyCode.KUnknown: return Keys.Print;
                case KeyCode.KExecute: return(Keys.Execute);

                case KeyCode.KPrintscreen: return(Keys.PrintScreen);

                //            KeyCode.KPrintscreen: return Keys.Snapshot; // Snapshot is the same as PrintScreen
                case KeyCode.KInsert: return(Keys.Insert);

                case KeyCode.KDelete: return(Keys.Delete);

                case KeyCode.KHelp: return(Keys.Help);

                case KeyCode.K0: return(Keys.D0);

                case KeyCode.K1: return(Keys.D1);

                case KeyCode.K2: return(Keys.D2);

                case KeyCode.K3: return(Keys.D3);

                case KeyCode.K4: return(Keys.D4);

                case KeyCode.K5: return(Keys.D5);

                case KeyCode.K6: return(Keys.D6);

                case KeyCode.K7: return(Keys.D7);

                case KeyCode.K8: return(Keys.D8);

                case KeyCode.K9: return(Keys.D9);

                case KeyCode.KA: return(Keys.A);

                case KeyCode.KB: return(Keys.B);

                case KeyCode.KC: return(Keys.C);

                case KeyCode.KD: return(Keys.D);

                case KeyCode.KE: return(Keys.E);

                case KeyCode.KF: return(Keys.F);

                case KeyCode.KG: return(Keys.G);

                case KeyCode.KH: return(Keys.H);

                case KeyCode.KI: return(Keys.I);

                case KeyCode.KJ: return(Keys.J);

                case KeyCode.KK: return(Keys.K);

                case KeyCode.KL: return(Keys.L);

                case KeyCode.KM: return(Keys.M);

                case KeyCode.KN: return(Keys.N);

                case KeyCode.KO: return(Keys.O);

                case KeyCode.KP: return(Keys.P);

                case KeyCode.KQ: return(Keys.Q);

                case KeyCode.KR: return(Keys.R);

                case KeyCode.KS: return(Keys.S);

                case KeyCode.KT: return(Keys.T);

                case KeyCode.KU: return(Keys.U);

                case KeyCode.KV: return(Keys.V);

                case KeyCode.KW: return(Keys.W);

                case KeyCode.KX: return(Keys.X);

                case KeyCode.KY: return(Keys.Y);

                case KeyCode.KZ: return(Keys.Z);

                case KeyCode.KLgui: return(Keys.LeftWin);

                case KeyCode.KRgui: return(Keys.RightWin);

                case KeyCode.KApplication: return(Keys.Apps);

                case KeyCode.KSleep: return(Keys.Sleep);

                case KeyCode.KKP0: return(Keys.NumPad0);

                case KeyCode.KKP1: return(Keys.NumPad1);

                case KeyCode.KKP2: return(Keys.NumPad2);

                case KeyCode.KKP3: return(Keys.NumPad3);

                case KeyCode.KKP4: return(Keys.NumPad4);

                case KeyCode.KKP5: return(Keys.NumPad5);

                case KeyCode.KKP6: return(Keys.NumPad6);

                case KeyCode.KKP7: return(Keys.NumPad7);

                case KeyCode.KKP8: return(Keys.NumPad8);

                case KeyCode.KKP9: return(Keys.NumPad9);

                case KeyCode.KKPMultiply: return(Keys.Multiply);

                case KeyCode.KPlus /*KPlus is not a physical key*/:
                case KeyCode.KKPPlus: return(Keys.Add);

                case KeyCode.KSeparator: return(Keys.Separator);

                case KeyCode.KKPMinus: return(Keys.Subtract);

                case KeyCode.KKPComma:
                case KeyCode.KKPPeriod:
                case KeyCode.KKPDecimal: return(Keys.Decimal);

                case KeyCode.KThousandsseparator:
                case KeyCode.KDecimalseparator: return(Keys.Decimal);                                      // See ISO/IEC 9995-4

                case KeyCode.KKPDivide: return(Keys.Divide);

                case KeyCode.KF1: return(Keys.F1);

                case KeyCode.KF2: return(Keys.F2);

                case KeyCode.KF3: return(Keys.F3);

                case KeyCode.KF4: return(Keys.F4);

                case KeyCode.KF5: return(Keys.F5);

                case KeyCode.KF6: return(Keys.F6);

                case KeyCode.KF7: return(Keys.F7);

                case KeyCode.KF8: return(Keys.F8);

                case KeyCode.KF9: return(Keys.F9);

                case KeyCode.KF10: return(Keys.F10);

                case KeyCode.KF11: return(Keys.F11);

                case KeyCode.KF12: return(Keys.F12);

                case KeyCode.KF13: return(Keys.F13);

                case KeyCode.KF14: return(Keys.F14);

                case KeyCode.KF15: return(Keys.F15);

                case KeyCode.KF16: return(Keys.F16);

                case KeyCode.KF17: return(Keys.F17);

                case KeyCode.KF18: return(Keys.F18);

                case KeyCode.KF19: return(Keys.F19);

                case KeyCode.KF20: return(Keys.F20);

                case KeyCode.KF21: return(Keys.F21);

                case KeyCode.KF22: return(Keys.F22);

                case KeyCode.KF23: return(Keys.F23);

                case KeyCode.KF24: return(Keys.F24);

                case KeyCode.KNumlockclear: return(Keys.NumLock);

                case KeyCode.KScrolllock: return(Keys.Scroll);

                case KeyCode.KLshift: return(Keys.LeftShift);

                case KeyCode.KRshift: return(Keys.RightShift);

                case KeyCode.KLctrl: return(Keys.LeftCtrl);

                case KeyCode.KRctrl: return(Keys.RightCtrl);

                case KeyCode.KLalt: return(Keys.LeftAlt);

                case KeyCode.KRalt: return(Keys.RightAlt);

                case KeyCode.KACBack: return(Keys.BrowserBack);

                case KeyCode.KACForward: return(Keys.BrowserForward);

                case KeyCode.KACRefresh: return(Keys.BrowserRefresh);

                case KeyCode.KACStop: return(Keys.BrowserStop);

                case KeyCode.KACSearch: return(Keys.BrowserSearch);

                case KeyCode.KACBookmarks: return(Keys.BrowserFavorites);

                case KeyCode.KACHome: return(Keys.BrowserHome);

                case KeyCode.KAudiomute: return(Keys.VolumeMute);

                case KeyCode.KVolumedown: return(Keys.VolumeDown);

                case KeyCode.KVolumeup: return(Keys.VolumeUp);

                case KeyCode.KAudionext: return(Keys.MediaNextTrack);

                case KeyCode.KAudioprev: return(Keys.MediaPreviousTrack);

                case KeyCode.KAudiostop: return(Keys.MediaStop);

                case KeyCode.KAudioplay: return(Keys.MediaPlayPause);

                case KeyCode.KMail: return(Keys.LaunchMail);

                case KeyCode.KMediaselect: return(Keys.SelectMedia);

                case KeyCode.KApp1: return(Keys.LaunchApplication1);

                case KeyCode.KApp2: return(Keys.LaunchApplication2);

                //            KeyCode.KSemicolon: return Keys.Oem1; // Same as OemSemicolon
                case KeyCode.KSemicolon: return(Keys.OemSemicolon);

                case KeyCode.KEquals: return(Keys.OemPlus);

                case KeyCode.KComma: return(Keys.OemComma);

                case KeyCode.KMinus: return(Keys.OemMinus);

                case KeyCode.KPeriod: return(Keys.OemPeriod);

                //            KeyCode.KUnknown: return Keys.Oem2; // Same as OemQuestion
                case KeyCode.KSlash: return(Keys.OemQuestion);

                //            KeyCode.KUnknown: return Keys.Oem3; // Same as OemTilde
                case KeyCode.KBackquote: return(Keys.OemTilde);

                //            KeyCode.KUnknown: return Keys.Oem4; // Same as OemOpenBrackets
                case KeyCode.KLeftbracket: return(Keys.OemOpenBrackets);

                //            KeyCode.KUnknown: return Keys.Oem5; // Same as OemPipe
                case KeyCode.KBackslash when scancode != Scancode.ScancodeNonusbackslash: return(Keys.OemPipe);    // SDL maps both Oem5 and Oem102 to the same KeyCode; we have to select based on scancode

                //            KeyCode.KUnknown: return Keys.Oem6; // Same as OemCloseBrackets
                case KeyCode.KRightbracket: return(Keys.OemCloseBrackets);

                //            KeyCode.KUnknown: return Keys.Oem7; // same as OemQuotes
                case KeyCode.KQuote: return(Keys.OemQuotes);

                // SDL maps OEM8 to Backquote which is already OEMTilde; this key is often used to open in game consoles and such; I think we should keep it as is
                // to avoid UK players being unable to access that feature
                // http://kbdlayout.info/kbdsmsfi
                // KeyCode.KBackquote: return Keys.Oem8;
                //            KeyCode.KUnknown: return Keys.Oem102; // same as OemBackslash
                case KeyCode.KBackslash when scancode == Scancode.ScancodeNonusbackslash: return(Keys.OemBackslash);

                //            KeyCode.KUnknown: return Keys.Attn;
                case KeyCode.KCrsel: return(Keys.CrSel);

                case KeyCode.KExsel: return(Keys.ExSel);

                //            KeyCode.KUnknown: return Keys.EraseEof;
                //            KeyCode.KUnknown: return Keys.Play;
                //            KeyCode.KUnknown: return Keys.Zoom;
                //            KeyCode.KUnknown: return Keys.NoName;
                //            KeyCode.KUnknown: return Keys.Pa1;
                //            KeyCode.KUnknown: return Keys.OemClear;
                case KeyCode.KKPEnter: return(Keys.NumPadEnter);

                default: return(Keys.None);
                }
            }
Ejemplo n.º 25
0
 /// <summary>
 /// Return keycode from scancode.
 /// </summary>
 public Key GetKeyFromScancode(Scancode scancode)
 {
     Runtime.ValidateRefCounted(this);
     return(Input_GetKeyFromScancode(handle, scancode));
 }
Ejemplo n.º 26
0
 public virtual void KeyPressed(KeyConstant key, Scancode scancode, bool isRepeat)
 {
 }
Ejemplo n.º 27
0
 internal static extern Key Input_GetKeyFromScancode(IntPtr handle, Scancode scancode);
 /// <inheritdoc/>
 public void SpoofKeyPress(Scancode scancode, Key key, Boolean ctrl, Boolean alt, Boolean shift)
 {
     SpoofKeyDown(scancode, key, ctrl, alt, shift);
     SpoofKeyUp(scancode, key, ctrl, alt, shift);
 }
 /// <inheritdoc/>
 public void SpoofKeyUp(Scancode scancode, Key key, Boolean ctrl, Boolean alt, Boolean shift)
 {
     var data = Ultraviolet.Messages.CreateMessageData<SDL2EventMessageData>();
     data.Event = new SDL_Event()
     {
         key = new SDL_KeyboardEvent()
         {
             type = (uint)SDL_EventType.KEYUP,
             windowID = (uint)Ultraviolet.GetPlatform().Windows.GetPrimary().ID,
             keysym = new SDL_Keysym()
             {
                 keycode = (SDL_Keycode)key,
                 scancode = (SDL_Scancode)scancode,
                 mod =
                     (ctrl ? SDL_Keymod.CTRL : SDL_Keymod.NONE) |
                     (alt ? SDL_Keymod.ALT : SDL_Keymod.NONE) |
                     (shift ? SDL_Keymod.SHIFT : SDL_Keymod.NONE),
             },
         }
     };
     Ultraviolet.Messages.Publish(SDL2UltravioletMessages.SDLEvent, data);
 }
Ejemplo n.º 30
0
 static Key TranslateKey(Scancode scan)
 {
     Key result = Key.Unknown;
     if (map.ContainsKey(scan))
     {
         result = map[scan];
     }
     return result;
 }
Ejemplo n.º 31
0
 public override void KeyPressed(KeyConstant key, Scancode scancode, bool is_repeat) => Elements.CallFocus("KeyPressed", key, scancode, is_repeat);
Ejemplo n.º 32
0
 /// <summary>
 /// Return name of key from scancode.
 /// </summary>
 public string GetScancodeName(Scancode scancode)
 {
     Runtime.ValidateRefCounted(this);
     return(Marshal.PtrToStringAnsi(Input_GetScancodeName(handle, scancode)));
 }
Ejemplo n.º 33
0
 internal static extern bool Input_GetScancodePress(IntPtr handle, Scancode scancode);
Ejemplo n.º 34
0
 /// <inheritdoc/>
 public void SpoofKeyPress(Scancode scancode, Key key, Boolean ctrl, Boolean alt, Boolean shift)
 {
     SpoofKeyDown(scancode, key, ctrl, alt, shift);
     SpoofKeyUp(scancode, key, ctrl, alt, shift);
 }
Ejemplo n.º 35
0
 static Key TranslateKey(Scancode scan)
 {
     return Sdl2KeyMap.GetKey(scan);
 }