Skip to content

fix: 修复未处理 WM_SYSKEYDOWN/WM_SYSKEYUP 导致的异常 - #374

Open
FeJS8888 wants to merge 2 commits into
x-ege:masterfrom
FeJS8888:fix-syskey-error
Open

fix: 修复未处理 WM_SYSKEYDOWN/WM_SYSKEYUP 导致的异常#374
FeJS8888 wants to merge 2 commits into
x-ege:masterfrom
FeJS8888:fix-syskey-error

Conversation

@FeJS8888

@FeJS8888 FeJS8888 commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

#373

Summary by CodeRabbit

  • Bug 修复
    • 改进键盘事件处理:现已支持系统按键(如 Alt 组合),并与普通按键走同一路径。
    • 系统按键的按下、抬起以及首次按下状态可正确识别与传递到事件队列。
    • 统一并优化键盘消息解析逻辑,确保键状态映射、计数与队列推送结果一致。

Copilot AI review requested due to automatic review settings July 25, 2026 02:31
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 694837ba-592b-47c5-a19c-ced053330cde

📥 Commits

Reviewing files that changed from the base of the PR and between 8662536 and cf8b66c.

📒 Files selected for processing (1)
  • src/keyboard.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/keyboard.cpp

Walkthrough

扩展系统键盘消息的解析、窗口分发及按键状态更新,使 WM_SYSKEYDOWNWM_SYSKEYUP 进入与普通键盘消息一致的处理流程。

Changes

系统按键处理

Layer / File(s) Summary
系统按键编码解析
src/keyboard.cpp
_getkeypeekkeypeekallkey 将系统按键纳入按下、抬起及首次按下编码处理,并调整功能键返回编码。
系统按键状态分发
src/graphics.cpp
窗口过程、消息处理和 on_key 回调将系统按键路由至现有状态映射、计数及队列流程。

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ltabsyy

Poem

我是兔子,蹦过按键林,
Alt 的回声也听得清。
按下抬起排成队,
系统消息不再隐。
耳朵一抖,代码成春。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次修复的核心:补处理 WM_SYSKEYDOWN/WM_SYSKEYUP 以消除异常。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #373 where key state could get “stuck” (e.g., Ctrl) when Alt is involved, by ensuring system key messages (WM_SYSKEYDOWN/WM_SYSKEYUP) are handled consistently alongside normal key messages in the Windows message pipeline.

Changes:

  • Treat WM_SYSKEYDOWN/WM_SYSKEYUP as key down/up events when consuming keyboard messages (src/keyboard.cpp).
  • Extend UI/control key dispatch and internal key state tracking to include system key down/up messages (src/graphics.cpp).
  • Ensure the window procedure routes WM_SYSKEYDOWN/WM_SYSKEYUP into the existing key handling path (src/graphics.cpp).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/keyboard.cpp Adds WM_SYSKEYDOWN/WM_SYSKEYUP support when reading key messages from msgkey_queue.
src/graphics.cpp Routes system key messages through on_key() and UI control key dispatch to keep keystatemap accurate.

Comment thread src/keyboard.cpp
Comment on lines 28 to +30
while (pg->msgkey_queue->pop(msg)) {
if (msg.message == WM_CHAR || msg.message == WM_KEYDOWN) {
if (msg.message == WM_KEYDOWN) {
if (msg.message == WM_CHAR || msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) {
if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) {

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/graphics.cpp`:
- Around line 640-642: Update the WM_SYSKEYDOWN and WM_SYSKEYUP handling in the
window procedure so these messages are forwarded to DefWindowProcW after the
on_key callback, rather than exiting through return 0; preserve existing
handling for ordinary key messages and any intentional WM_SYSCOMMAND
interception.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 75a6fb38-844a-44c5-8bca-ee690149700d

📥 Commits

Reviewing files that changed from the base of the PR and between e85aa27 and 8662536.

📒 Files selected for processing (2)
  • src/graphics.cpp
  • src/keyboard.cpp

Comment thread src/graphics.cpp
Comment on lines +640 to +642
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Files:"
git ls-files | rg '(^|/)src/graphics\.cpp$|src/graphics\.(h|hpp)$' || true

echo
echo "Outline:"
ast-grep outline src/graphics.cpp --view compact 2>/dev/null | sed -n '1,220p' || true

echo
echo "Relevant message handling region:"
nl -ba src/graphics.cpp | sed -n '600,730p'

echo
echo "on_key usages/definition:"
rg -n "on_key|WM_SYSKEYDOWN|WM_SYSKEYUP|WM_KEYUP|DefWindowProcW|WM_SYSCOMMAND|WM_MENU|WM_ACTIVATE" src/graphics.cpp

Repository: x-ege/xege

Length of output: 258


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Relevant message handling region:"
awk '{printf "%6d\t%s\n", NR, $0}' src/graphics.cpp | sed -n '600,730p'

echo
echo "on_key usages/def and relevant Windows messages:"
grep -n "on_key\|WM_SYSKEYDOWN\|WM_SYSKEYUP\|WM_KEYUP\|DefWindowProcW\|WM_SYSCOMMAND\|WM_MENU\|WM_ACTIVATE" src/graphics.cpp || true

echo
echo "Search on_key declaration/implementation:"
grep -Rn "on_key" src | sed -n '1,120p'

Repository: x-ege/xege

Length of output: 6841


🌐 Web query:

Microsoft Windows WM_SYSKEYDOWN message DefWindowProc Alt F10 system menu documentation

💡 Result:

The WM_SYSKEYDOWN message is sent to a window when a system key is pressed—specifically when the user presses the F10 key (which activates the menu bar) or holds down the ALT key while pressing another key [1][2]. Regarding the interaction with DefWindowProc and the activation of the system menu: 1. Handling of F10 and ALT: When a window procedure receives the WM_SYSKEYDOWN message, it is critical to pass the message to the DefWindowProc function if the application does not intend to handle the keystroke itself [2]. The system uses the WM_SYSKEYDOWN message to track the state of these keys for system-level commands [3]. 2. Mechanism of Menu Activation: DefWindowProc does not typically trigger the menu activation immediately upon receiving the WM_SYSKEYDOWN message for F10. Instead, it tracks the state of the F10 key [3]. When the subsequent WM_KEYUP message for F10 is received, DefWindowProc checks that internal state and, if F10 was pressed, sends a WM_SYSCOMMAND message with the SC_KEYMENU parameter to the window [3]. This WM_SYSCOMMAND message is what actually activates the menu bar [4][3]. 3. Recommendations: If you need to intercept or prevent the default menu activation triggered by ALT or F10, you should handle the WM_SYSCOMMAND message in your window procedure [5][4]. By catching WM_SYSCOMMAND where wParam is equal to SC_KEYMENU, you can prevent the default behavior (by returning 0 without calling DefWindowProc) or implement custom logic to display your own menu or handle the event differently [5][4]. If you simply "block" the WM_SYSKEYDOWN message without letting it reach DefWindowProc, you may interfere with the operating system's ability to process standard system commands [2]. Therefore, the recommended practice is to allow the system to process the keys via DefWindowProc and instead override the resulting action by intercepting the WM_SYSCOMMAND message [5][4][3].

Citations:


不要吞掉 WM_SYSKEYDOWN/WM_SYSKEYUP 的默认窗口处理。

这条分支调用完 on_key 后直接 break,最终从 return 0 退出;WM_SYSKEYDOWN/SM_SYSKEYUP 需要传给 DefWindowProcW 才能让系统继续处理 F10/Alt 等系统键盘状态,否则对应 WM_SYSCOMMAND 行为(如菜单激活)可能失效。转发消息前如需拦截,可先处理业务回调并额外转发/拦截 WM_SYSCOMMAND

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/graphics.cpp` around lines 640 - 642, Update the WM_SYSKEYDOWN and
WM_SYSKEYUP handling in the window procedure so these messages are forwarded to
DefWindowProcW after the on_key callback, rather than exiting through return 0;
preserve existing handling for ordinary key messages and any intentional
WM_SYSCOMMAND interception.

@FeJS8888
FeJS8888 requested a review from Copilot July 26, 2026 22:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants