I am filtering keyboard messages delivered to a specific win32 application by hooking GetMessage/PeekMessage, it works fine except for context menu. For example, when i right click blank area in notepad and press P to paste text from clipboard, i am not seeing GetMessaage(WM_KEYDOWN...) invoked at all. Is there any other apis that are used to get keyboard messages from message queue for context menu? BTW, for specific reason, i cannot use WH_KEYBOARD_LL for this purpose.
Asked
Active
Viewed 158 times
0
-
Menu keys are delivered by WM_MENUCHAR. – Raymond Chen Aug 15 '20 at 02:47
-
Unfortunately i am not seeing a WM_MENUCHAR(0x0120) message retrieved in GetMessage/PeekMessage – herb Aug 15 '20 at 11:03
-
the interesting thing is WH_GETMESSAGE hook can intercept these WM_KEYDOWN/UP messages – herb Aug 15 '20 at 13:59
-
`WM_MENUCHAR` is a sent message, and `WH_GETMESSAGE` hooks do not see sent messages. – Raymond Chen Aug 15 '20 at 14:18
-
WH_GETMESSAGE only sees posted messages. Use WH_CALLWNDPROC to hook sent messages. – Remy Lebeau Aug 15 '20 at 23:28
-
guys, you are not answering my question, my question is why WM_KEYDOWN/UP is not monitored in GetMessage/PeekMessage hook, I am using Detours hook, not WH_XXX – herb Aug 16 '20 at 00:27
1 Answers
0
This is by design.
I can reproduce this problem on Notepad/Edit control. After discussing with related engineer, it is certain that the menu that appears after pressing the right mouse button and press P can receive WM_KEYDOWN
, but the WM_KEYDOWN
message is handled inside the menu and it is converted to other messages. This is why we cannot monitor in GetMessage
. We don't know the message processing mechanism inside the system menu, but if you are interested, you can draw a menu and test it yourself.

Strive Sun
- 5,988
- 1
- 9
- 26
-
@herb Hi, if the answer is useful to you, don't forget to mark it. This can be beneficial to other community members reading this thread. [How to accept an answer?](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) – Strive Sun Aug 28 '20 at 08:03