Prevent MacOS from showing the accent selection popup in Flutter

Issue

I’m developing a Flutter desktop app and I have to process raw keyboard input (custom drawn control that handles user input).

For this I’m using a TextInputClient and a TextInputConfiguration that gets registered via TextInput.attach(client, config).

I have everything working but when I long-press a key on MacOS then I receive one key press and then MacOS shows the accent selection popup.

Is there any way to prevent MacOS from doing that? I tried all different variations of TextInputConfiguration parameters but MacOS doesn’t care.

The text handling is too much code to paste it here but when needed or not obvious I can create a small sample that shows the problem.

Solution

Ok, so after digging though the internet I found a solution.
I let it here so that other people can find it, too.

The solution is an application wide setting. I didn’t find a solution to enable / disable that behaviour on a TextInput instance base.

In the end it comes down to setting a preference for your application that you don’t want the tap-and-hold but the auto repeat behaviour.

You can do that in the MacOS integration layer of your Flutter application:

AppDelegate.swift

Add the following method to the already existing AppDelegate:

override func applicationDidFinishLaunching(_ notification: Notification) {
    UserDefaults.standard.set(false, forKey: "ApplePressAndHoldEnabled");
}

And that’s all.

Answered By – Michael Lamers

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *