winapikeyboard-eventswindows-messages

a question about getting keyboard stroke on context menu


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.


Solution

  • 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.