flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond

Home Page:https://flutter.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[windows] Pressing Right-Shift turns on caps lock and locks in a TextField

ChargerMc opened this issue · comments

On flutter desktop, Right-Shift turns on caps lock and locks in a TextField

Code excample:

TextField(
              decoration: InputDecoration(
                  alignLabelWithHint: true,
                  labelText: 'Escribe el mensaje...',
                  hintText: '...',
                  labelStyle: TextStyle(
                      fontSize:
                          Theme.of(context).textTheme.headline6.fontSize)),
              maxLines: 8,
              enableInteractiveSelection: true,
              controller: messageController,
              onChanged: (value) {

              },
            ), 

Flutter Doctor:


> Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel dev, 1.26.0-17.1.pre, on Microsoft Windows [Version 10.0.19042.746], locale es-MX)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.4)   
[√] Android Studio (version 4.0)
[√] VS Code (version 1.53.0)
[√] Connected device (3 available)

• No issues found!

Hi @ChargerMc
Thanks for filing the issue, I can reproduce it on Windows (not on macOS), the right-shift key is acting as CAPS lock on the dev and master

code sample
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      theme: ThemeData.dark(),
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Material App Bar'),
      ),
      body: Center(
        child: TextField(
          decoration: InputDecoration(
              alignLabelWithHint: true,
              labelText: 'Escribe el mensaje...',
              hintText: '...',
              labelStyle: TextStyle(
                  fontSize: Theme.of(context).textTheme.headline6.fontSize)),
          maxLines: 8,
          enableInteractiveSelection: true,
          onChanged: (value) {},
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {},
      ),
    );
  }
}
flutter doctor -v
[√] Flutter (Channel dev, 1.26.0-17.2.pre, on Microsoft Windows [Version 10.0.19042.746], locale en-US)
    • Flutter version 1.26.0-17.2.pre at C:\Users\Taha\Code\flutter_dev
    • Framework revision 79b49b9e10 (5 days ago), 2021-02-03 15:33:39 -0800
    • Engine revision 2c527d6c7e
    • Dart version 2.12.0 (build 2.12.0-259.8.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.
[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.4)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.8.30907.101
    • Windows 10 SDK version 10.0.18362.0
[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Users\Taha\Code\android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code (version 1.53.0)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.19.0
[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19042.746]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 88.0.4324.150
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 88.0.705.63
• No issues found!
[√] Flutter (Channel master, 1.26.0-18.0.pre.215, on Microsoft Windows [Version 10.0.19042.746], locale en-US)
    • Flutter version 1.26.0-18.0.pre.215 at C:\Users\Taha\Code\flutter_master
    • Framework revision f3c10bd23a (3 hours ago), 2021-02-08 21:52:03 -0800
    • Engine revision b04955656c
    • Dart version 2.13.0 (build 2.13.0-0.0.dev)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.
[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.4)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.8.30907.101
    • Windows 10 SDK version 10.0.18362.0
[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Users\Taha\Code\android-studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code (version 1.53.0)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.19.0
[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19042.746]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 88.0.4324.150
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 88.0.705.63
• No issues found!

Thank you

Hi @ChargerMc
Thanks for filing the issue, I can reproduce it on Windows (not on macOS), the right-shift key is acting as CAPS lock on the dev and master

code sample

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      theme: ThemeData.dark(),
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Material App Bar'),
      ),
      body: Center(
        child: TextField(
          decoration: InputDecoration(
              alignLabelWithHint: true,
              labelText: 'Escribe el mensaje...',
              hintText: '...',
              labelStyle: TextStyle(
                  fontSize: Theme.of(context).textTheme.headline6.fontSize)),
          maxLines: 8,
          enableInteractiveSelection: true,
          onChanged: (value) {},
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {},
      ),
    );
  }
}

flutter doctor -v
Thank you

Great, thank u!

There is a similar issue in macos. For example when you write CAPITAL LETTERS, you cannot delete the Text if the String ends with a capital one. This happens when using textfield or cupertinotextfield and seems to be a Flutter binding library problem.

Im still waiting for the team to solve this issue since 4 months ago.

flutter doctor -v
[✓] Flutter (Channel master, 1.27.0-2.0.pre.102, on Microsoft Windows [Version 10.0.19042.804], locale en-US)
    • Flutter version 1.27.0-2.0.pre.102 at C:\Users\Taha\Code\flutter_master
    • Framework revision b2e05062b6 (4 hours ago), 2021-02-15 03:56:03 -0500
    • Engine revision 1d537824d6
    • Dart version 2.13.0 (build 2.13.0-30.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Taha\Code\SDK
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = C:\Users\Taha\Code\SDK
    • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.
[✓] Chrome - develop for the web
    • Chrome at C:\Users\Taha\AppData\Local\Google\Chrome\Application\chrome.exe
[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.5)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.8.31005.135
    • Windows 10 SDK version 10.0.18362.0
[✓] Android Studio (version 4.1.0)
    • Android Studio at C:\Users\Taha\Code\android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[✓] VS Code (version 1.53.2)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.19.0
[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19042.804]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 88.0.4324.150
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 84.0.522.52
• No issues found!

Just in case if it helps anyone. This doesn't happen on 1.26.0-1.0.pre.

Some additional details about this:

  • It's more than caps lock when this happens, since special keys also gets their counterparts (like when I press "." I get ">")
  • When I press left shift, this mode is entered, I can only exit it when I press right shift, and if I enter this by right shift, I can exit it by left shift only, attempting to exit it using the same shift does not work.

flutter doctor:
[√] Flutter (Channel dev, 1.26.0-17.2.pre, on Microsoft Windows [Version 10.0.19042.804], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.3)
[√] Android Studio (version 4.1.0)
[√] IntelliJ IDEA Ultimate Edition (version 2020.3)
[√] Connected device (4 available)

Some additional details about this:

  • It's more than caps lock when this happens, since special keys also gets their counterparts (like when I press "." I get ">")
  • When I press left shift, this mode is entered, I can only exit it when I press right shift, and if I enter this by right shift, I can exit it by left shift only, attempting to exit it using the same shift does not work.

flutter doctor:
[√] Flutter (Channel dev, 1.26.0-17.2.pre, on Microsoft Windows [Version 10.0.19042.804], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.3)
[√] Android Studio (version 4.1.0)
[√] IntelliJ IDEA Ultimate Edition (version 2020.3)
[√] Connected device (4 available)

Yes its more like a turning on sticky keys. And for me it always happens on right shift key. Left shift key behaves properly. And when this happens backspace doesn't work randomly.

Hi @ChargerMc
Thanks for filing the issue, I can reproduce it on Windows (not on macOS), the right-shift key is acting as CAPS lock on the dev and master

code sample
flutter doctor -v
Thank you

Actually, for me it's like Pressing Right Shift is behave like Holding Shift Key...

Try :
Type Something then use left shift to type a character, then just press left arrow it will select text with out holding shift key also type a special character if number key pressed.

Test with this code...
https://api.flutter.dev/flutter/services/LogicalKeyboardKey-class.html#services.LogicalKeyboardKey.1

I got the same issue, any word on a fix or where the code hosts to implement a temporary fix? For me, the left shift turns it off "caps lock" (e.g. inserts non-capital letters, and numerical keys 1234 etc. While once pressed the right shift key, it inserts capitalized letters, and symbolic keys !@#$ etc.

The root cause of this issue: #77179.

Although the raw keyboard API should have modifier state check as well. @gspencergoog Can you take a look why it isn't working as intended?

Some more input: In a text field when I press right shift it gets hooked and acts like I never released the key. Even if I press it again and release it, it still stays hooked. If I press the left shift, the right shift unhooks and everything works fine again.

I've seen this before in Anydesk. It has to do with the operating system not noticing a key release.
Only difference with Anydesk is that there it was random. In flutter on, Windows at least, it happens every time the right shift is pressed. Weird considering it only happens with the right shift.

Here's my flutter doctor:

[√] Flutter (Channel stable, 2.0.1, on Microsoft Windows [Version 10.0.19042.844], locale el-GR)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.0)
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.52.1)
[√] Connected device (3 available)

• No issues found!

Hi, can you give us any updates on this defect? When can we expect it to be fixed?

@Coimbra1984 If everything goes right, I should be able to merge the fixing PR within a few weeks.

Have there been any developments on a fix for this?

@dkwingsmt Even if it's p4 bug, the entire user experience got affected.

There is a another way to fix this? maybe with an package? any idea?

@Coimbra1984 If everything goes right, I should be able to merge the fixing PR within a few weeks.

Just echoing that this is a very severe bug IMO. My windows desktop app has a login screen and it is basically unusable because users cannot login without special instructions. The reason being is that once they type in their email address the right shift key is used to enter the @ sign which then locks the field into uppercase mode. This also then triggers another bug which is that if the last character in a field is uppercase you can't delete the text.

If the user ignores that the email is in uppercase (which is ok) they then move onto the password field. They don't know that the caps lock key is stuck on so they think they are entering their correct password but in fact they are not. They continue to try to login and then get locked out because they try too many times with a bad password.

The only workaround really is to tell the users is that when they login to NOT use the RIGHT SHIFT key. This is very unnatural. I do wish this bug would get some priority as it is making Windows non-usable for my users. @dkwingsmt @gspencergoog

We literally cannot release our product because of this bug. We also have a login screen and anyone that knows how to type properly will invariably use the right shift key to input the "@" character. Why is this taking so long to fix? This is a HUGE bug.

This seems to only be an issue with native keyboards on a laptop or with a bluetooth connect keyboard. A USB keyboard works as expected.

We literally cannot release our product because of this bug. We also have a login screen and anyone that knows how to type properly will invariably use the right shift key to input the "@" character. Why is this taking so long to fix? This is a HUGE bug.

Same problem here! Our release is blocked by this issue. Can we help with a contribution in any way?

This seems to only be an issue with native keyboards on a laptop or with a bluetooth connect keyboard. A USB keyboard works as expected.

The problem happens around any keyboard. I have it on my mechanical keyboard (USB) just as much as a laptop keyboard. It's not hardware-related. Purely the result of processing state wrongly on the application side (maybe even compensate by performing os-level state changes itself, given it seems to mess with vs code/sublime pressed hot-keys also).

I am pretty much in the same boat, have an application with a login screen. This bug effectively so hindering that whatever parts of the platform are usable are now completely unusable since the most elementary computer interaction (typing) doesn't work properly.

I tried to take a peek at the WndProc handling earlier, hoping to trace it to some native part that could be easily modified, the windows message gets absorbed into some deeper layers of the main flutter engine/dart. I had hoped by now somebody would have already proposed an actual fix ( it's been over 2 months, and there's no hint of any form of progress).

Same bug here. Also blocks our release.

flutter/engine#25882 should have fixed this issue. Please wait until the engine is rolled into the framework, or wait until the next version.
Since this is a widespread issue I'm gonna leave this issue open until confirmed by many. In the mean time, you might workaround this issue by wrapping the root of the app with the following widget:

class ShiftRightFixer extends StatefulWidget {
  ShiftRightFixer({this.child});
  final Widget child;
  @override
  State<StatefulWidget> createState() => _ShiftRightFixerState();
}

class _ShiftRightFixerState extends State<ShiftRightFixer> {
  final FocusNode focus = FocusNode(skipTraversal: true, canRequestFocus: false);
  @override
  Widget build(BuildContext context) {
    return Focus(
      focusNode: focus,
      onKey: (_, RawKeyEvent event) {
        return event.physicalKey == PhysicalKeyboardKey.shiftRight ?
          KeyEventResult.handled : KeyEventResult.ignored;
      },
      child: widget.child,
    );
  }
}

Also, my deep apology for leaving this issue for so long and causing widespread inconvenience. Although I have been working on the keyboard system full time, in retrospect this issue could have been resolved earlier. There are both the complexity of the issue as well as the misjudgement on my side. I'll take the blame, but please know that we're reading all the reports and care about experience of Flutter on all platforms.

Thanks for the PR!

WidgetsBinding.instance.window.onKeyData ??= (_) => true;

Unfortunately this doesn't help me. When I add this statement (actually it's WidgetsBinding.instance?.window.onKeyData ??= (_) => true;) I'm unable to enter any character into an input field.

@Coimbra1984 I've updated the original comment with a new workaround (ShiftRightFixer ). Can you check again?

@Coimbra1984 I've updated the original comment with a new workaround (ShiftRightFixer ). Can you check again?

This one return event.physicalKey == PhysicalKeyboardKey.shiftRight; gives me the following error:
The return type 'bool' isn't a 'KeyEventResult', as required by the closure's context.

@Coimbra1984 Can you try the current one? (Wasn't aware that the callback signature change has been relanded.)

@Coimbra1984 Can you try the current one? (Wasn't aware that the callback signature change has been relanded.)

It works! but, there's a fix for this? when I try to write in spanish the word "holá", I'm getting this
image
there's any workaround?

During testing the above (which works), I reached to a horrible defect. I have a German keyboard, to make a @ sign we have to press ALT-GR+Q key. When I do this, something happens which makes windows completely confused. I'm unable to enter anything after that even in other programs, I need to restart my PC. We tested this behaviour on two different machines, against the flutter stable, beta and dev channel. All show the same problem. Is this part of this defect here, or must I open a new one for that?

@ChargerMc @Coimbra1984 Neither of your problems is not part of this issue (which I feel bad to hear). Can you check if there are existing issues, and if not, open a new one with reproduction step? Thank you.

@Coimbra1984 The AltGr issue is probably #78005.

@cbracken Is the "holá" issue a known one?

@cbracken Is the "holá" issue a known one?

Yes, there's a issue: #75510

flutter/engine#25882 should have fixed this issue. Please wait until the engine is rolled into the framework, or wait until the next version.
Since this is a widespread issue I'm gonna leave this issue open until confirmed by many. In the mean time, you might workaround this issue by wrapping the root of the app with the following widget:

class ShiftRightFixer extends StatefulWidget {
  ShiftRightFixer({this.child});
  final Widget child;
  @override
  State<StatefulWidget> createState() => _ShiftRightFixerState();
}

class _ShiftRightFixerState extends State<ShiftRightFixer> {
  final FocusNode focus = FocusNode(skipTraversal: true, canRequestFocus: false);
  @override
  Widget build(BuildContext context) {
    return Focus(
      focusNode: focus,
      onKey: (_, RawKeyEvent event) {
        return event.physicalKey == PhysicalKeyboardKey.shiftRight ?
          KeyEventResult.handled : KeyEventResult.ignored;
      },
      child: widget.child,
    );
  }
}

Also, my deep apology for leaving this issue for so long and causing widespread inconvenience. Although I have been working on the keyboard system full time, in retrospect this issue could have been resolved earlier. There are both the complexity of the issue as well as the misjudgement on my side. I'll take the blame, but please know that we're reading all the reports and care about experience of Flutter on all platforms.

This fix worked for me--I wrapped my login screen class in this to fix login issues. Thanks!

flutter/engine#25882 should have fixed this issue. Please wait until the engine is rolled into the framework, or wait until the next version.
Since this is a widespread issue I'm gonna leave this issue open until confirmed by many. In the mean time, you might workaround this issue by wrapping the root of the app with the following widget:

class ShiftRightFixer extends StatefulWidget {
  ShiftRightFixer({this.child});
  final Widget child;
  @override
  State<StatefulWidget> createState() => _ShiftRightFixerState();
}

class _ShiftRightFixerState extends State<ShiftRightFixer> {
  final FocusNode focus = FocusNode(skipTraversal: true, canRequestFocus: false);
  @override
  Widget build(BuildContext context) {
    return Focus(
      focusNode: focus,
      onKey: (_, RawKeyEvent event) {
        return event.physicalKey == PhysicalKeyboardKey.shiftRight ?
          KeyEventResult.handled : KeyEventResult.ignored;
      },
      child: widget.child,
    );
  }
}

Also, my deep apology for leaving this issue for so long and causing widespread inconvenience. Although I have been working on the keyboard system full time, in retrospect this issue could have been resolved earlier. There are both the complexity of the issue as well as the misjudgement on my side. I'll take the blame, but please know that we're reading all the reports and care about experience of Flutter on all platforms.

thanks that worked...

flutter/engine#25882 should have fixed this issue. Please wait until the engine is rolled into the framework, or wait until the next version.
Since this is a widespread issue I'm gonna leave this issue open until confirmed by many. In the mean time, you might workaround this issue by wrapping the root of the app with the following widget:

class ShiftRightFixer extends StatefulWidget {
  ShiftRightFixer({this.child});
  final Widget child;
  @override
  State<StatefulWidget> createState() => _ShiftRightFixerState();
}

class _ShiftRightFixerState extends State<ShiftRightFixer> {
  final FocusNode focus = FocusNode(skipTraversal: true, canRequestFocus: false);
  @override
  Widget build(BuildContext context) {
    return Focus(
      focusNode: focus,
      onKey: (_, RawKeyEvent event) {
        return event.physicalKey == PhysicalKeyboardKey.shiftRight ?
          KeyEventResult.handled : KeyEventResult.ignored;
      },
      child: widget.child,
    );
  }
}

Also, my deep apology for leaving this issue for so long and causing widespread inconvenience. Although I have been working on the keyboard system full time, in retrospect this issue could have been resolved earlier. There are both the complexity of the issue as well as the misjudgement on my side. I'll take the blame, but please know that we're reading all the reports and care about experience of Flutter on all platforms.

thanks, this worked for me aswell.

Waiting for a fix for this issue, it's still happening at flutter 2.2 version

@imariman have written a quick fix (hack) for this bug at this page: #78005 It works! So I published my first Flutter Windows app with this hack. (Now we are waiting for a permanent fix from Flutter team. But it does not matter now.)

I'll close this issue for now but feel free comment if there are any related problems, and reopen this issue if deemed necessary (don't forget to append your Flutter version in the report).

For non-related problems mentioned in this thread, please move forward to their respective issue page (we will fix them for sure).

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.