Skip to content

Skip the window key (both left and right) on Windows#84292

Closed
RPRX wants to merge 1 commit into
flutter:masterfrom
XTLS:rprx-patch-1
Closed

Skip the window key (both left and right) on Windows#84292
RPRX wants to merge 1 commit into
flutter:masterfrom
XTLS:rprx-patch-1

Conversation

@RPRX

@RPRX RPRX commented Jun 9, 2021

Copy link
Copy Markdown

This PR solves the following issues:

Related to:

解决了一个影响广泛的、非常影响 Windows 中文用户体验的、release-blocker 级别的 BUG。

详述:上个月我遇到了它,即 backspace 键不起作用,反复试了一段时间后发现从英文切换到中文输入就会这样,一度以为是微软拼音的问题,十分郁闷,吃饭路上研究了一下输入法原理,又觉得不应该是它的问题。继续测试,发现 window + space 切换键盘布局就会导致此问题,同时 window + backspace 却能神奇地解除此状态,这就很迷惑了...决定调试下 flutter 框架的代码,最后发现是 window 键“卡住”了,被误认为一直按着,而 backspace 等键则会被忽略(只剩 IME 能用):

final bool isMacOS = keyEvent.data is RawKeyEventDataMacOs;
if (!_nonModifierKeys.contains(key) ||
keysPressed.difference(isMacOS ? _macOsModifierKeys : _modifierKeys).length > 1 ||
keysPressed.difference(_interestingKeys).isNotEmpty) {
// If the most recently pressed key isn't a non-modifier key, or more than
// one non-modifier key is down, or keys other than the ones we're interested in
// are pressed, just ignore the keypress.
return;
}

所以问题很明显了:window + * 的系统热键会导致 flutter 窗口失去焦点,从而没有捕获到 window 键弹起的消息。
然而 Windows 上的 flutter 程序并不需要响应系统热键,始终忽略 window 键是一个合适的选择。
我先是修改了 win32_window.cpp,发现不起作用,经反复调试,推测是因为 raw_keyboard.dart 中的 methodChannel 调用的是预编译的 flutter_windows.dll,于是转而修改 raw_keyboard_windows.dart,完美解决问题:

    // The window key (both left and right) should also be skipped, because the
    // following window key up event at present will not be captured by flutter
    // when it loses focus, which will cause the window key to be considered as
    // still being pressed, and will result in confusing bugs. For example, the
    // backspace key will be ineffective after user changed IME by pressing the
    // "window + space" system hotkey (or other hotkeys like "window + r").
    //
    // In addition, the window key should be handled by the system, so it is OK
    // to skip it here. And the accompanying key will be hijacked by the system
    // completely, so no additional character will be entered in this case.

考虑到还有非常多的人遇到了此问题,且这个 BUG 是 release-blocker 级别的,不解决就无法发布软件,所以今天用这个号提交 PR。同时麻烦跟进其它系统中的类似问题,希望 flutter 对桌面端的支持尽快完善,谢谢。

@flutter-dashboard flutter-dashboard Bot added the framework flutter/packages/flutter repository. See also f: labels. label Jun 9, 2021
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@google-cla google-cla Bot added the cla: yes label Jun 9, 2021
@Piinks Piinks added a: desktop Running on desktop a: text input Entering text in a text field or keyboard related problems a: internationalization Supporting other languages or locales. (aka i18n) a: typography Text rendering, possibly libtxt labels Jun 10, 2021
@HansMuller HansMuller requested a review from dkwingsmt June 10, 2021 23:33
@dkwingsmt

Copy link
Copy Markdown
Contributor

I investigated this problem and submitted PR flutter-team-archive/engine#26757 that likely solves this issue. Thanks for your contribution all the same, especially the reproducing steps.

@RPRX

RPRX commented Jun 15, 2021

Copy link
Copy Markdown
Author

I investigated this problem and submitted PR flutter/engine#26757 that likely solves this issue. Thanks for your contribution all the same, especially the reproducing steps.

十分感谢,请问实测可以解决此问题吗?

@dkwingsmt

Copy link
Copy Markdown
Contributor

是的,实测在master上重现了这个问题,而在这个PR之后这个问题同样的步骤无法重现。

@RPRX

RPRX commented Jun 23, 2021

Copy link
Copy Markdown
Author

是的,实测在master上重现了这个问题,而在这个PR之后这个问题同样的步骤无法重现。

感谢,实测在我的电脑上 master channel 已解决此问题(即包含 flutter-team-archive/engine#26757 的 flutter engine,前两天才能 upgrade 到)

目前我这里还有三个比较迫切的影响 Windows 中文用户体验的小问题需要解决:

  1. 微软拼音输入法,输入拼音后不选词而是按 ESC,其它软件如 chrome 的行为是丢弃拼音,而 flutter 的行为是保留拼音。
  2. TextField 尚不支持 CTRL+Z(撤销)和 CTRL+Y(重做),也就是 TextEditingController 尚不支持历史记录,希望有个官方实现。
  3. TextField 同时选中中文和英文时,背景色上下边缘是不连贯的,这个视觉效果比较另类,目前所有平台都是这样。

希望桌面端上 flutter 的行为更符合预期,同时期待更丝滑的交互体验,加油,再次感谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop a: internationalization Supporting other languages or locales. (aka i18n) a: text input Entering text in a text field or keyboard related problems a: typography Text rendering, possibly libtxt framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

3 participants