<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Arrow keys cause unichar field to be non zero in OSX</title>
		<link>http://www.allegro.cc/forums/view/606860</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 30 Mar 2011 18:05:33 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve just noticed that my textbox, in OSX started writing those square [] looking characters when I pressed the arrow keys in OSX. Therefore the unichar field was non zero which is not consistent with Windows.</p><p>Up : 63232<br />Down : 63233<br />F1 : 63236</p><p>Docs say: This may be zero or negative if the event was generated for a non-visible &quot;character&quot;, such as an arrow key. </p><p>Those numbers don&#39;t look zero or non negative</p><p>Since it happens in KeyChar, I have no way of filtering out these keys other than checking each one which seems wrong.</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Mon, 28 Mar 2011 09:28:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Apparently this might depend on the OS X version:</p><p><a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=3194187&amp;group_id=5665&amp;atid=105665">http://sourceforge.net/tracker/index.php?func=detail&amp;aid=3194187&amp;group_id=5665&amp;atid=105665</a></p><p>Someone should try to fix it, otherwise it makes it hard to write code that works consistently across platforms.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Mon, 28 Mar 2011 11:07:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Could you possibly filter out Apple&#39;s special Unicode range and return 0 when you hit a key in that range?</p><p>ex:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>unicode <span class="k3">&gt;</span> xxxxx <span class="k3">&amp;</span><span class="k3">&amp;</span> unicode <span class="k3">&lt;</span> yyyyy<span class="k2">)</span>
<span class="k2">{</span>
   <span class="c">//Apple being *special*</span>
   unicode <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Mon, 28 Mar 2011 19:34:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What should we do about these keys?</p><p>backspace key -&gt; ascii 8<br />tab key -&gt; ascii 9<br />return key -&gt; ascii 13<br />esc key -&gt; ascii 27</p><p>They seem to work on other platforms besides OSX right now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Mon, 28 Mar 2011 20:44:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What do these give for you on OSX? this is why in my gui I do if(unichar &gt;= &#39; &#39;) and that works on Linux and Windows.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Tue, 29 Mar 2011 00:50:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606860/910426#target">Elias</a> said:</div><div class="quote"><p>What should we do about these keys?</p></div></div><p>

They should produce the ascii codes you have written there. The documentation should be clarified.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 29 Mar 2011 03:24:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve attached a patch that fixes my problem, and should make Allegro consistent with Windows and Linux, I basically filter out Apple&#39;s specialness.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Tue, 29 Mar 2011 08:14:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I guess so. I applied a modified version of your patch to the 5.1 branch. Please test.  5.0.2 should be coming soon.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 29 Mar 2011 11:44:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, in OSX backspace gives me 127 instead of 8 it seems - so the &lt;= 32 would not work for it either.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 29 Mar 2011 15:00:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The SDL library has simlilar behaviour for backspace on OSX.<br />The person who ported my SDL program from linux/windows to OSX had to re-convert the backspace (unicode==127) to ascii code 8.<br />It&#39;s especially confusing that SDL has key identifier SDLK_DELETE=127, and normally all numbers &lt;= 127 are expected to be ascii key codes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 29 Mar 2011 15:25:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think it would be nice to have Backspace return 8 on OS X as well.</p><p>On X we return 127 for Delete. On Windows (wine) we return 0.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Tue, 29 Mar 2011 17:40:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I hadn&#39;t noticed the backspace / delete issue because I have a case for both of these in the form of allegro keycode, but yes, I do think an if(unicode == 127) { unicode = 8; } would be nice. But if backspace shows up as that, then does that mean delete shows up as ascii 8?</p><p>Also, I think I may know why Apple does this. On my MacBook Pro, in OSX, my key which says Delete on it actually deletes while the same key in Windows does backspace (for the whole OS). So I think this is intended by Apple and may not actually be a problem.</p><p>Windows is not emulated or anything, I run 7 Nativity with Apple provided Boot Camp drivers.</p><p>Also, your modified version works as expected for me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Tue, 29 Mar 2011 18:36:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oww, after a very short googling I find that the key labeled &#39;delete&#39; on a MacBook is the one that performs a backspace : To erase current character you&#39;d do fn+Delete (*).<br />No that wonder that it gets confusing for cross-platform libraries...<br />Should allegro tell which key the user pressed (&#39;delete&#39;) or what he wanted to do ?</p><p>(*) Does fn+Delete cause an event with unicode = &#39;the character for delete&#39;, different from &#39;the character for backspace&#39; ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 29 Mar 2011 20:36:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Audric</p><p>For me, in OSX, on my MBP: </p><p>Delete: 127<br />Fn + Delete: 8</p><p>Windows:<br />Inverse</p><p>Since it is inverse for every other application I say, lets not touch it, the patch Peter Wang uploaded makes it work consistent with everything else. I do not think we should invert Apples inversion since all software on OSX is already inverted.</p><p>In OSX, the delete key for me does the opposite that it does in Windows and I&#39;m fine with that since all other software acts like this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Tue, 29 Mar 2011 20:42:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>On my mac mini (using a normal, non-mac keyboard plugged into the USB port) the Backspace key produces 127 and the DEL key produces 63272. Both keys work as expected in native OSX applications. If we document Allegro to produce 8 for backspace and 127 for delete it seems we&#39;d have to adjust for that.</p><p>An alternative solution would be to get rid of control codes and return 0 for backspace and delete as well as tab, return and esc. It seems to have things working on Macs you have to check the key code anyway - so allowing those ASCII codes under windows and linux would just mean more broken keyboard input code.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 29 Mar 2011 20:53:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I agree, I think it would be a lot less confusing if across all platforms, all non renderable characters, arrow, fn, insert, del, backspace, etc, should just produce a Unichar of 0, which will indicate to the user to check the keycode.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Tue, 29 Mar 2011 21:01:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So the keycode is always correct and the unichar is bogus?</p><p>I think the only thing that makes sense in 5.0 is to either a) document it, or b) convert OS X unichars to something sensible.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Tue, 29 Mar 2011 22:16:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The idea would be that someone writing a text entry box would follow this logic only:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>event.unichar <span class="k3">!</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span>
    <a href="http://www.allegro.cc/manual/al_ustr_insert_chr"><span class="a">al_ustr_insert_chr</span></a><span class="k2">(</span>editbox, pos, event.unichar<span class="k2">)</span><span class="k2">;</span>
<span class="k1">else</span> <span class="k2">{</span>
    check event.key <span class="k1">for</span> DEL<span class="k3">/</span>Backspace<span class="k3">/</span>Cursor<span class="k3">/</span>Tab<span class="k3">/</span>Esc<span class="k3">/</span>Return
<span class="k2">}</span>
</pre></div></div><p>

Right now you can also sometimes use ascii codes... if we return always 0 you couldn&#39;t.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 29 Mar 2011 22:49:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This is how I have always been doing it:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span>keycode <span class="k3">=</span><span class="k3">=</span> ALLEGRO_KEY_BACKSPACE<span class="k2">)</span>
<span class="k2">{</span>
<span class="k2">}</span>
<span class="k1">else</span> <span class="k1">if</span> <span class="k2">(</span>unichar <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">32</span><span class="k2">)</span>
<span class="k2">{</span>
<span class="k2">}</span>
</pre></div></div><p>
I realize not all <span class="source-code">unichar <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">32</span></span> are going to be true printable characters, but that doesn&#39;t bother me. The point is, checking for non-zero isn&#39;t very correct anyway.</p><p>I don&#39;t think it should be assumed that Allegro translates or modifies the <span class="source-code">unichar</span> in any way whatsoever. And I really don&#39;t think we should go about changing 5.0&#39;s behavior.</p><p>For 5.2 if the consensus is to zero out the <span class="source-code">unichar</span>, then go for it. But I don&#39;t see why it&#39;s absolutely necessary. To me the field should simply be what the OS reports as the printable <span class="source-code">unichar</span>. I don&#39;t consider LEFT/RIGHT/DELETE printable characters, so why would I ever think to use <span class="source-code">unichar</span> for them?</p><p>To me, this is primarily a documentation issue.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Tue, 29 Mar 2011 23:01:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yea I do it Matthew&#39;s way too, but it&#39;s up to the Allegro Team, either one works for me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Wed, 30 Mar 2011 01:27:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606860/910644#target">Matthew Leverton</a> said:</div><div class="quote"><p> I don&#39;t consider LEFT/RIGHT/DELETE printable characters, so why would I ever think to use unichar for them?</p></div></div><p>

There&#39;s possibly more keys, maybe F keys produce non-standard unicode as well under OSX.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 30 Mar 2011 01:27:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, F Keys, Arrow, Insert, basically all the ones my patch blocked out.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Wed, 30 Mar 2011 01:37:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606860/910673#target">Elias</a> said:</div><div class="quote"><p> There&#39;s possibly more keys, maybe F keys produce non-standard unicode as well under OSX.
</p></div></div><p>I don&#39;t really care... Unless I&#39;m checking every unichar code to see if it maps to some printable character with the font I&#39;m using at the time, whether or not we mask some keys or not is irrelevant. </p><p>And if I do that (validate that the unichar key is in the font), then it doesn&#39;t matter if Apple uses strange characters. They wouldn&#39;t exist in the font, and they would be ignored.</p><p>To me unichar == something to be printed. The only time I would use unichar is if I want to print a string to the screen. If the user presses F1 when entering his name and that produces some strange symbol on OS X, I couldn&#39;t care less. If I&#39;m looking for function keys or anything else that maps to a physical key, I&#39;m just using the keycode constants.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Wed, 30 Mar 2011 02:23:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, but what I&#39;m saying is we have these possibilities:
</p><ul><li><p>A) .unichar is always 0 for non-printable characters</p></li><li><p>B) .unichar reports whatever the OS reports</p></li><li><p>C) .unichar returns 8,9,13,27,127 but blocks out other non-printable characters</p></li></ul><p>

C is what is currently in SVN after the patch to set .unichar to 0 for those OSX symbols.</p><p>A is what I&#39;m proposing - the only change to SVN would be that the five extra control codes we still put into .unichar are also set to 0.</p><p>B is how it worked before.</p><p>And both A and B seem better than C to me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 30 Mar 2011 16:25:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Backspace, Tab, Enter, Escape, etc. have ASCII codes associated with them, so to me, that&#39;s what they should produce if you &quot;type&quot; them. Ctrl-A also produces 1, Ctrl-B produces 2, etc.</p><p>I can see the reasoning for all three choices, but my preferences would be: C, B, A.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Peter Wang)</author>
		<pubDate>Wed, 30 Mar 2011 17:26:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I wondered about &quot;non-printable&quot;, and in the context of text input in an allegro game or utility, I guess the question always resolves to ML&#39;s point:<br />If the unicode value has a character in the font (shipped with the game), it&#39;s printable.<br />If it doesn&#39;t, it doesn&#39;t make sense to &quot;accept&quot; it as user input, as he won&#39;t see what he&#39;s just typed.</p><p>One big advantage of this approach is that if you provide a rudimentary font, let&#39;s say only part of latin characters, the user can still swap it with a bigger font in order to support more characters or a different set, without recompiling or anything.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Wed, 30 Mar 2011 17:38:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606860/910963#target">Peter Wang</a> said:</div><div class="quote"><p>
Ctrl-A also produces 1, Ctrl-B produces 2, etc.
</p></div></div><p>

Ah, I forgot about those. So in my A5 text box by simply checking for ASCII 8 instead of KEY_BACKSPACE Ctrl-H will work as backspace. I&#39;m sold for option C now <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>The EVENT_KEY_CHAR .unichar documentation should have something like this added:</p><p>Some special keys will set the .unichar field to their standard ASCII code: Backspace=8, Tab=9, Return=13, Escape=27, Delete=127. In addition if you press the Control key together with A to Z the .unichar field will have the values 1 to 26. For example Ctrl-A will set .unichar to 1 and both the Backspace key and Ctrl-H will set it to 8.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 30 Mar 2011 18:05:33 +0000</pubDate>
	</item>
</rss>
