Exemple #1
0
 NSEvent MakeEvent(string c, NSEventType type, double epochTime, nint winID)
 {
     return(NSEvent.KeyEvent(type, CoreGraphics.CGPoint.Empty,
                             (NSEventModifierMask)0, epochTime, winID,
                             NSGraphicsContext.CurrentContext,
                             c, c, false, 0));
 }
Exemple #2
0
        // http://lists.apple.com/archives/cocoa-dev/2008/Apr/msg01696.html
        void FlashMenu()
        {
            var f35   = ((char)0xF726).ToString();
            var blink = new NSMenuItem("* blink *")
            {
                KeyEquivalent = f35,
            };
            var f35Event = NSEvent.KeyEvent(
                NSEventType.KeyDown, CGPoint.Empty, NSEventModifierMask.CommandKeyMask, 0, 0,
                NSGraphicsContext.CurrentContext, f35, f35, false, 0);

            AddItem(blink);
            PerformKeyEquivalent(f35Event);
            RemoveItem(blink);
        }
Exemple #3
0
        void FlashMenu(MDMenuItem item)
        {
            var f35 = ((char)0xF726).ToString();

            if (blink != null)
            {
                RemoveItem(blink);
            }
            blink = new NSMenuItem(item.CommandEntry.GetCommand(item.Manager).DisplayName)
            {
                KeyEquivalent = f35,
            };

            AddItem(blink);

            var f35Event = NSEvent.KeyEvent(
                NSEventType.KeyDown, CGPoint.Empty, NSEventModifierMask.CommandKeyMask, 0, 0,
                NSGraphicsContext.CurrentContext, f35, f35, false, 0);

            PerformKeyEquivalent(f35Event);
        }
        public static NSEvent ConvertKeyEvent(IntPtr hwnd, MSG msg, ref NSEventModifierMask flags)
        {
            NSView vuWrap       = (NSView)ObjCRuntime.Runtime.GetNSObject(hwnd);
            var    windowNumber = vuWrap?.Window?.WindowNumber ?? 0;

            var key     = (Keys)msg.wParam.ToInt32();
            var keyCode = NSKeyFromKeys((Keys)key);

            if (!keyCode.HasValue)
            {
                return(null);
            }

            bool down = msg.message == Msg.WM_KEYDOWN;

            if (down)
            {
                switch (key)
                {
                case Keys.ShiftKey: flags |= NSEventModifierMask.ShiftKeyMask; break;

                case Keys.ControlKey: flags |= NSEventModifierMask.ControlKeyMask; break;

                case Keys.Menu: flags |= NSEventModifierMask.AlternateKeyMask; break;
                }
            }
            else
            {
                switch (key)
                {
                case Keys.ShiftKey: flags &= ~NSEventModifierMask.ShiftKeyMask; break;

                case Keys.ControlKey: flags &= ~NSEventModifierMask.ControlKeyMask; break;

                case Keys.Menu: flags &= ~NSEventModifierMask.AlternateKeyMask; break;
                }
            }

            Debug.WriteLine($"Converting message: {msg.message}, {keyCode}");

            string keys = GetCharactersForKeyPress((ushort)keyCode.Value, flags, ref deadKeyState);

            uint   dummy             = 0;
            string keysIgnoringFlags = GetCharactersForKeyPress((ushort)keyCode.Value, 0, ref dummy);

            NSEvent e = null;

            switch (msg.message)
            {
            case Msg.WM_KEYDOWN:
                e = NSEvent.KeyEvent(NSEventType.KeyDown, CGPoint.Empty, flags, NSDate.Now.SecondsSinceReferenceDate, windowNumber, null, keys, keysIgnoringFlags, false, (ushort)keyCode.Value);
                break;

            case Msg.WM_KEYUP:
                e = NSEvent.KeyEvent(NSEventType.KeyUp, CGPoint.Empty, flags, NSDate.Now.SecondsSinceReferenceDate, windowNumber, null, keys, keysIgnoringFlags, false, (ushort)keyCode.Value);
                break;

            default:
                break;
            }

            return(e);
        }