Ejemplo n.º 1
0
        private OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Keyboard);
            MacOSKeyCode code     = (MacOSKeyCode)0;
            char         charCode = '\0';

            switch (evt.KeyboardEventKind)
            {
            case KeyboardEventKind.RawKeyDown:
            case KeyboardEventKind.RawKeyRepeat:
            case KeyboardEventKind.RawKeyUp:
                GetCharCodes(inEvent, out code, out charCode);
                mKeyPressArgs.KeyChar = charCode;
                break;
            }

            OpenTK.Input.Key key;
            switch (evt.KeyboardEventKind)
            {
            case KeyboardEventKind.RawKeyRepeat:
                if (InputDriver.Keyboard[0].KeyRepeat)
                {
                    goto case KeyboardEventKind.RawKeyDown;
                }
                break;

            case KeyboardEventKind.RawKeyDown:
                Keymap.TryGetValue(code, out key);
                // Legacy keyboard API
                InputDriver.Keyboard[0].SetKey(key, (uint)code, true);

                // Raise KeyDown for new keyboard API
                mKeyDownArgs.Key = key;
                KeyDown(this, mKeyDownArgs);

                // Raise KeyPress for new keyboard API
                if (!Char.IsControl(mKeyPressArgs.KeyChar))
                {
                    OnKeyPress(mKeyPressArgs);
                }
                return(OSStatus.NoError);

            case KeyboardEventKind.RawKeyUp:
                Keymap.TryGetValue(code, out key);
                // Legacy keyboard API
                InputDriver.Keyboard[0].SetKey(key, (uint)code, false);

                // Raise KeyUp for new keyboard API
                mKeyUpArgs.Key = key;
                KeyUp(this, mKeyUpArgs);
                return(OSStatus.NoError);

            case KeyboardEventKind.RawKeyModifiersChanged:
                ProcessModifierKey(inEvent);
                return(OSStatus.NoError);
            }

            return(OSStatus.EventNotHandled);
        }
Ejemplo n.º 2
0
        private OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Keyboard);
            MacOSKeyCode code     = (MacOSKeyCode)0;
            char         charCode = '\0';

            switch (evt.KeyboardEventKind)
            {
            case KeyboardEventKind.RawKeyDown:
            case KeyboardEventKind.RawKeyRepeat:
            case KeyboardEventKind.RawKeyUp:
                GetCharCodes(inEvent, out code, out charCode);
                mKeyPressArgs.KeyChar = charCode;
                break;
            }

            switch (evt.KeyboardEventKind)
            {
            case KeyboardEventKind.RawKeyRepeat:
                if (InputDriver.Keyboard[0].KeyRepeat)
                {
                    goto case KeyboardEventKind.RawKeyDown;
                }
                break;

            case KeyboardEventKind.RawKeyDown:
            {
                OpenTK.Input.Key key;
                if (Keymap.TryGetValue(code, out key))
                {
                    InputDriver.Keyboard[0][key] = true;
                    OnKeyPress(mKeyPressArgs);
                }
                return(OSStatus.NoError);
            }

            case KeyboardEventKind.RawKeyUp:
            {
                OpenTK.Input.Key key;
                if (Keymap.TryGetValue(code, out key))
                {
                    InputDriver.Keyboard[0][key] = false;
                }
                return(OSStatus.NoError);
            }

            case KeyboardEventKind.RawKeyModifiersChanged:
                ProcessModifierKey(inEvent);
                return(OSStatus.NoError);
            }

            return(OSStatus.EventNotHandled);
        }
Ejemplo n.º 3
0
        void ProcessKeyDown(MacOSKeyCode code)
        {
            Key key;

            Keymap.TryGetValue(code, out key);

            // Legacy keyboard API
            KeyboardDevice keyboard = InputDriver.Keyboard[0];

            keyboard.SetKey(key, (uint)code, true);

            // Raise KeyDown for new keyboard API
            mKeyDownArgs.Key       = key;
            mKeyDownArgs.Modifiers = keyboard.GetModifiers();

            KeyDown(this, mKeyDownArgs);

            // Raise KeyPress for new keyboard API
            if (!Char.IsControl(mKeyPressArgs.KeyChar))
            {
                OnKeyPress(mKeyPressArgs);
            }
        }
Ejemplo n.º 4
0
        OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
        {
            MacOSKeyCode code     = (MacOSKeyCode)0;
            char         charCode = '\0';

            //Debug.Print("Processing Keyboard event {0}", (KeyboardEventKind)evt.EventKind);

            switch ((KeyboardEventKind)evt.EventKind)
            {
            case KeyboardEventKind.RawKeyDown:
            case KeyboardEventKind.RawKeyRepeat:
            case KeyboardEventKind.RawKeyUp:
                code     = API.GetEventKeyboardKeyCode(inEvent);
                charCode = API.GetEventKeyboardChar(inEvent);
                break;
            }

            Key tkKey;

            if (!Keymap.TryGetValue(code, out tkKey))
            {
                Debug.Print("{0} not mapped, ignoring press.", code);
                return(OSStatus.NoError);
            }

            switch ((KeyboardEventKind)evt.EventKind)
            {
            case KeyboardEventKind.RawKeyRepeat:
                Keyboard.KeyRepeat = true;
                goto case KeyboardEventKind.RawKeyDown;

            case KeyboardEventKind.RawKeyDown:
                Keyboard.Set(tkKey, true);
                RaiseKeyPress(charCode);
                return(OSStatus.NoError);

            case KeyboardEventKind.RawKeyUp:
                Keyboard.Set(tkKey, false);
                return(OSStatus.NoError);

            case KeyboardEventKind.RawKeyModifiersChanged:
                ProcessModifierKey(inEvent);
                return(OSStatus.NoError);
            }
            return(OSStatus.EventNotHandled);
        }