<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: What&#8217;s broken in the WM_KEYDOWN/WM_CHAR input model?</title>
	<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/</link>
	<description>A blog on the development of the NGEDIT text editor</description>
	<pubDate>Wed, 07 Jan 2009 10:38:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
		<item>
		<title>By: J</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-97325</link>
		<dc:creator>J</dc:creator>
		<pubDate>Thu, 29 Nov 2007 21:01:07 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-97325</guid>
		<description>Julien, that might be a workable solution in a stand-alone app that you control. Nowadays, in my ViEmus, I am subclassing Visual Studio's editor window, and I have rely on just the messages that arrive to the window, so it's not a solution.

In any case, if you end up testing the approach, I'd be grateful to learn how it went.</description>
		<content:encoded><![CDATA[<p>Julien, that might be a workable solution in a stand-alone app that you control. Nowadays, in my ViEmus, I am subclassing Visual Studio&#8217;s editor window, and I have rely on just the messages that arrive to the window, so it&#8217;s not a solution.</p>
<p>In any case, if you end up testing the approach, I&#8217;d be grateful to learn how it went.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Picalausa</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-95421</link>
		<dc:creator>Julien Picalausa</dc:creator>
		<pubDate>Fri, 23 Nov 2007 20:23:42 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-95421</guid>
		<description>First, I would like to say that this post was very inspiring for me. I learned some useful things from it :)


Also, this is a simple way that seems to work for me when trying to get the information of WM_KEYDOWN and WM_CHAR together:

BOOL MyTranslateMessage(const MSG* message)
{
	if (!TranslateMessage(message))
		return FALSE;

	MSG translated_message;
	BOOL has_translated_message =PeekMessage(&#38;translated_message, message-&#62;hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE);

	if (has_translated_message)
	{
		//Do stuff with the data of the translated message and the original message
	}
	else
	{
		//Do stuff with the message
	}

}

I cannot guarantee this to be entirely flawless since I've only been using it for testing purposes, but logically, you generate one message with TranslateMessage that you retrieve and remove directly with PeekMessage, so unless something else posts WM_CHAR messages to your message queue, you should be fine.</description>
		<content:encoded><![CDATA[<p>First, I would like to say that this post was very inspiring for me. I learned some useful things from it <img src='http://blog.ngedit.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also, this is a simple way that seems to work for me when trying to get the information of WM_KEYDOWN and WM_CHAR together:</p>
<p>BOOL MyTranslateMessage(const MSG* message)<br />
{<br />
	if (!TranslateMessage(message))<br />
		return FALSE;</p>
<p>	MSG translated_message;<br />
	BOOL has_translated_message =PeekMessage(&amp;translated_message, message-&gt;hwnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE);</p>
<p>	if (has_translated_message)<br />
	{<br />
		//Do stuff with the data of the translated message and the original message<br />
	}<br />
	else<br />
	{<br />
		//Do stuff with the message<br />
	}</p>
<p>}</p>
<p>I cannot guarantee this to be entirely flawless since I&#8217;ve only been using it for testing purposes, but logically, you generate one message with TranslateMessage that you retrieve and remove directly with PeekMessage, so unless something else posts WM_CHAR messages to your message queue, you should be fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reuben</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-9956</link>
		<dc:creator>Reuben</dc:creator>
		<pubDate>Thu, 16 Nov 2006 02:21:34 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-9956</guid>
		<description>Thanks for the USEFUL information.

I have also noticed that you can trap the delete key as wParam = 46 in a WM_KEYDOWN message.
I have used this to stop users using the delete key in certain fields.</description>
		<content:encoded><![CDATA[<p>Thanks for the USEFUL information.</p>
<p>I have also noticed that you can trap the delete key as wParam = 46 in a WM_KEYDOWN message.<br />
I have used this to stop users using the delete key in certain fields.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-5784</link>
		<dc:creator>J</dc:creator>
		<pubDate>Thu, 07 Sep 2006 15:56:01 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-5784</guid>
		<description>Glenn, thanks a lot. I'm surprised but happy that this article is #2 if you Google for WM_CHAR and #6 for WM_KEYDOWN. It certainly ensures easy access to the info for other programmers trying to slay the same dragon. I'm now implementing full mapping support in my vi emulator for VS, and it's proving daunting!</description>
		<content:encoded><![CDATA[<p>Glenn, thanks a lot. I&#8217;m surprised but happy that this article is #2 if you Google for WM_CHAR and #6 for WM_KEYDOWN. It certainly ensures easy access to the info for other programmers trying to slay the same dragon. I&#8217;m now implementing full mapping support in my vi emulator for VS, and it&#8217;s proving daunting!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glenn</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-5775</link>
		<dc:creator>Glenn</dc:creator>
		<pubDate>Thu, 07 Sep 2006 07:47:32 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-5775</guid>
		<description>Kudos on this page. not much to add but I like it and found it to be extremely useful. Wanted to use that delete key myself! Nuts.</description>
		<content:encoded><![CDATA[<p>Kudos on this page. not much to add but I like it and found it to be extremely useful. Wanted to use that delete key myself! Nuts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pieter</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-5112</link>
		<dc:creator>pieter</dc:creator>
		<pubDate>Thu, 24 Aug 2006 14:17:25 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-5112</guid>
		<description>Well, say when receiving WM_KEYDOWN you remember the lParam, in order to compare it to the lParam of the next WM_CHAR message, but what with events that only generate WM_KEYDOWN (e.g the arrow keys)? There you are with your lParam. This would be a solution if with the WM_KEYDOWN some kind of flag was passed that says if you can expect a corresponding WM_CHAR or not. 
Still, thanks a lot for all the information.</description>
		<content:encoded><![CDATA[<p>Well, say when receiving WM_KEYDOWN you remember the lParam, in order to compare it to the lParam of the next WM_CHAR message, but what with events that only generate WM_KEYDOWN (e.g the arrow keys)? There you are with your lParam. This would be a solution if with the WM_KEYDOWN some kind of flag was passed that says if you can expect a corresponding WM_CHAR or not.<br />
Still, thanks a lot for all the information.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-2393</link>
		<dc:creator>J</dc:creator>
		<pubDate>Fri, 16 Jun 2006 09:30:46 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-2393</guid>
		<description>Dennis, thanks a lot for the pointer, and it may very well be that you are completely right. I will certainly research the issue. It will be incredibly useful, as establishing a reliable link betwen an WM_KEYDOWN and its WM_CHAR would allow me to recover 'keypresses' with all the relevant info and provide a solid key remapping model. I'll post about what I find out.

Thanks!</description>
		<content:encoded><![CDATA[<p>Dennis, thanks a lot for the pointer, and it may very well be that you are completely right. I will certainly research the issue. It will be incredibly useful, as establishing a reliable link betwen an WM_KEYDOWN and its WM_CHAR would allow me to recover &#8216;keypresses&#8217; with all the relevant info and provide a solid key remapping model. I&#8217;ll post about what I find out.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-2392</link>
		<dc:creator>Dennis</dc:creator>
		<pubDate>Fri, 16 Jun 2006 09:10:17 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-2392</guid>
		<description>Thanks for the great summary!

You mention that the concept of a keypress is lost, because WM_KEYDOWN and WM_CHAR are completely unrelated. However, at least according to MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/aboutkeyboardinput.asp) - I know you don't think highly of MSDN ;-) - WM_KEYDOWN messages contain a "previous key-state flag" in their lParam value. If this flag is 1, the WM_KEYDOWN message is a result of the autorepeat functionality. Further down on the same page they say, "The contents of the lParam parameter of a character message are identical to the contents of the lParam parameter of the key-down message that was translated to produce the character message."
So it should be possible to recognize keypress events by examining vanilla WM_KEYDOWN or cooked WM_CHAR events. Am I missing something?</description>
		<content:encoded><![CDATA[<p>Thanks for the great summary!</p>
<p>You mention that the concept of a keypress is lost, because WM_KEYDOWN and WM_CHAR are completely unrelated. However, at least according to MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/aboutkeyboardinput.asp) - I know you don&#8217;t think highly of MSDN <img src='http://blog.ngedit.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> - WM_KEYDOWN messages contain a &#8220;previous key-state flag&#8221; in their lParam value. If this flag is 1, the WM_KEYDOWN message is a result of the autorepeat functionality. Further down on the same page they say, &#8220;The contents of the lParam parameter of a character message are identical to the contents of the lParam parameter of the key-down message that was translated to produce the character message.&#8221;<br />
So it should be possible to recognize keypress events by examining vanilla WM_KEYDOWN or cooked WM_CHAR events. Am I missing something?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-886</link>
		<dc:creator>J</dc:creator>
		<pubDate>Wed, 03 May 2006 22:30:33 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-886</guid>
		<description>You're welcome. Google certainly likes this article - first page on both WM_CHAR and WM_KEYDOWN! I would certainly trade that, though, for a top spot in other keywords :) But at least programmer souls confused by the confusing input model will find this easily.</description>
		<content:encoded><![CDATA[<p>You&#8217;re welcome. Google certainly likes this article - first page on both WM_CHAR and WM_KEYDOWN! I would certainly trade that, though, for a top spot in other keywords <img src='http://blog.ngedit.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> But at least programmer souls confused by the confusing input model will find this easily.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Null</title>
		<link>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-885</link>
		<dc:creator>Null</dc:creator>
		<pubDate>Wed, 03 May 2006 22:22:16 +0000</pubDate>
		<guid>http://blog.ngedit.com/2005/06/13/whats-broken-in-the-wm_keydownwm_char-input-model/#comment-885</guid>
		<description>I'd also like to say thanks for sharing your findings and insight. And Google certainly seems to think highly of you. :)</description>
		<content:encoded><![CDATA[<p>I&#8217;d also like to say thanks for sharing your findings and insight. And Google certainly seems to think highly of you. <img src='http://blog.ngedit.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
