【问题标题】:Xamarin Mac Keyboard Input in different Windows不同 Windows 中的 Xamarin Mac 键盘输入
【发布时间】:2021-03-01 16:17:39
【问题描述】:

我已经为 mac 制作了我的第一个程序,一个使用 Xamarin Mac Cocoa 的简单终端仿真。 要绘制终端,我使用 XiaSharp。 要获得我使用的输入:

NSEvent.AddLocalMonitorForEventsMatchingMask(NSEventMask.KeyDown, KeyboardEventHandler);

private NSEvent KeyboardEventHandler(NSEvent keyEvent)
        {
            //FOR GL KEY

            if (keyEvent.KeyCode == 51) CSTSocket.SendByte(8); //Back
            else if (keyEvent.KeyCode == 36|| keyEvent.KeyCode == 76) CSTSocket.SendByte(13); //Enter
            else if (keyEvent.KeyCode == 49) CSTSocket.SendByte(32); //Space
            else if (keyEvent.KeyCode == 123) CSTSocket.SendByte(8); //Arrow Left
            else if (keyEvent.KeyCode == 126) CSTSocket.SendByte(11); //Arrow Up
            else if (keyEvent.KeyCode == 124) CSTSocket.SendByte(12); //Arrow Right
            else if (keyEvent.KeyCode == 125) CSTSocket.SendByte(22); //Arrow Down
        }

这适用于一个窗口,但如果我添加更多窗口:

[Export("newWindow:")]
        void NewDocument(NSObject sender)
        {
            // Get new window
            var storyboard = NSStoryboard.FromName("Main", null);
            var controller = storyboard.InstantiateControllerWithIdentifier("MainWindow") as NSWindowController;

            // Display
            controller.ShowWindow(this);

            // Set the title
            controller.Window.Title = (++WindowCount == 1) ? "Watermelon" : string.Format("Watermelon {0}", WindowCount);
        }

问题:我同时输入每个创建的窗口。

是否有一个事件可以让我确定哪个窗口处于活动状态,或者是否有另一个键盘事件我必须使用?

感谢任何建议

示例图片: Picture

【问题讨论】:

    标签: c# cocoa xamarin.mac


    【解决方案1】:

    我自己想通了:

    在 ViewController.cs 中,如果窗口有输入焦点,你可以获得一个布尔值:

    this.View.Windows.IsKeyWindow
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 2014-05-22
      • 1970-01-01
      • 1970-01-01
      • 2017-04-11
      • 2013-04-14
      • 2021-10-10
      相关资源
      最近更新 更多