From c96738ecd59e6b6f298be8e621da120401337f67 Mon Sep 17 00:00:00 2001 From: yixy <34703796+yixy-only@users.noreply.github.com> Date: Tue, 9 Jul 2024 02:07:31 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E5=A4=8D=20keystate=20?= =?UTF-8?q?=E5=9C=A8=E6=89=93=E5=BC=80=E5=AF=B9=E8=AF=9D=E6=A1=86=E5=90=8E?= =?UTF-8?q?=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98=20(#212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 GetOpenFileName 等打开对话框后,keystate 失效,但按键消息正常。原因是 GetKeyState 是通过处理按键消息来判断按键状态,需要在消息队列的窗口线程中使用。(如果在其它线程,猜测目前的底层实现是会获取最新创建的一个窗口线程的按键状态,因此一开始未打开对话框时是正常的。)。 chore: 忽略 ./out 目录 (Visual Studio Cmake生成目录) --- .gitignore | 1 + src/keyboard.cpp | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0771e018..ed85a741 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ /build /temp +/out diff --git a/src/keyboard.cpp b/src/keyboard.cpp index d9a97361..2a4ccc83 100644 --- a/src/keyboard.cpp +++ b/src/keyboard.cpp @@ -229,10 +229,7 @@ int keystate(int key) if (key < 0 || key >= MAX_KEY_VCODE) { return -1; } - SHORT s = GetKeyState(key); - if (((USHORT)s & 0x8000) == 0) { - pg->keystatemap[key] = 0; - } + return pg->keystatemap[key]; }