The MASM Forum

General => The Campus => Topic started by: shaikkareem on February 16, 2016, 10:50:03 PM

Title: WM_KEYFIRST and WM_KEYDOWN
Post by: shaikkareem on February 16, 2016, 10:50:03 PM
hi fellows,
while monitoring window messages through a window hook procedure, i faced this situation. the window procedure being called by the system when WM_KEYFIRST(0x0100) and WM_KEYDOWN(0x0100) messages are in the  thread message queue. i don't know how to distinguish between them because they both have same hex number that's why two time invocation of Hook procedure, which on comes earlier and later. please can someone help me to overcome this problem.
Title: Re: WM_KEYFIRST and WM_KEYDOWN
Post by: jj2007 on February 16, 2016, 11:14:36 PM
WM_KEYFIRST is not a message, it is the start of an enumeration. What you see is WM_KEYDOWN defined as WM_KEYFIRST+0.

WM_KEYFIRST                          equ 100h
WM_KEYDOWN                           equ 100h
WM_KEYUP                             equ 101h
WM_CHAR                              equ 102h
WM_DEADCHAR                          equ 103h
WM_SYSKEYDOWN                        equ 104h
WM_SYSKEYUP                          equ 105h
WM_SYSCHAR                           equ 106h
WM_SYSDEADCHAR                       equ 107h
WM_KEYLAST                           equ 108h
Title: Re: WM_KEYFIRST and WM_KEYDOWN
Post by: shaikkareem on February 17, 2016, 12:46:46 AM
here, when i press a key on keyboard, as i said, called two times the callback (hook procedure). so i have to always ignore the first one ( as assumed it as WM_KEYFIRST) and consider the second one . or completely misunderstanding. please explain....and one more thing i want to know about specifying the range (because we talking about WM_KEYFIRST & WM_KEYLAST) in GetMessage and PeekMessage. what they actually means in all contexts.
Title: Re: WM_KEYFIRST and WM_KEYDOWN
Post by: dedndave on February 17, 2016, 02:26:17 AM
WM_KEYFIRST is the first value associated with low-level keyboard messages
WM_KEYLAST is the last value associated with low-level keyboard messages

they are not actually valid message constant names
they are used to filter low-level keyboard messages as a group
Title: Re: WM_KEYFIRST and WM_KEYDOWN
Post by: dedndave on February 17, 2016, 02:30:57 AM
the hook procedure is called when the key is pressed and again when it is released
if you wanted to provide complete support, you would need to examine both to provide auto-repeat
Title: Re: WM_KEYFIRST and WM_KEYDOWN
Post by: shaikkareem on February 17, 2016, 03:54:30 PM
still unclear on how i can distinguish them, they both have same lParam. the only changing bits are 0-15 -> the repeat count is always 1 if i keep pressed down and 30- the previous key state which is set on long press.
Title: Re: WM_KEYFIRST and WM_KEYDOWN
Post by: dedndave on February 17, 2016, 09:55:57 PM
bit 31   :biggrin:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx)

all the links you need are on that page, highlighted with blue text
Title: Re: WM_KEYFIRST and WM_KEYDOWN
Post by: shaikkareem on February 17, 2016, 10:40:09 PM
Quote from: dedndave on February 17, 2016, 09:55:57 PM
bit 31   :biggrin:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx)

all the links you need are on that page, highlighted with blue text
:lol: