(Mis)using NSTextView to get a proper key interpretation? RRS feed

  • Question

  • User326160 posted


    I'm working on a Terminal App and I already have a working version using Qml.Net and .NET Core. Now I'm trying to port the current state to Xamarin.Forms as I think this will overall fit better with what I plan to do.

    I realized that Xamarin.Forms doesn't have any low level Key input interaction and the suggested way of handling this seems to be to intercept keys in the platform specific part of the Xamarin.Forms application and pass it to the platform independent part.

    This brings me to Xamarin.Mac as this is the first platform specific part I want to port to.

    Qt has some Key abstraction that is a little bit above the raw Key inputs. It already contains pre-edit states of the input device (or marked state) that gets active if you build characters using multiple keys (like â).

    The question now is: How do I get that level of preprocessing in Xamarin.Mac without having something from AppKit directly part of the Window? Is it possible to instantiate e.g. a NSTextView, pass it all the key events and get the preprocessed key / text events from that? Has anyone a better idea to solve the problem I mentioned?

    I don't plant to support all the different keyboard layout and language specific input behaviours explicitly especially when there is already something "in reach" that does all that already.

    Thanks for your answers!

    Tuesday, November 17, 2020 6:20 AM


  • User326160 posted

    I found a solution to this problem.

    I created a KeyHandlingContentView derived from ContentView in Xamarin.Forms and a custom Renderer for Mac that implements INSTextInputClient.

    This way the key events can be passed from that custom renderer to the Xamarin.Forms control.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, November 21, 2020 10:21 PM