<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Text input in Allegro 5</title>
		<link>http://www.allegro.cc/forums/view/609117</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 22 Dec 2011 23:24:18 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I would like to know how to input text using allegro. I am able to print it out, but can&#39;t figure out how to take it out from keyboard.</p><p>Please don&#39;t recommend to write 60 or more &quot;cases&quot; for &quot;ALLEGRO_KEY_DOWN_A .. Z&quot; and Shift/CapsLock, etc... And also GUI libraries.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Dvornik)</author>
		<pubDate>Thu, 22 Dec 2011 20:20:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can use <span class="source-code">ALLEGRO_EVENT_KEY_CHAR</span>, the unichar field contains the character that the user typed.  If he holds down Shift and presses the A key, event.keyboard.unichar will be &#39;A&#39;, etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Thu, 22 Dec 2011 20:27:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>When you get the aforementioned event, the text itself is in UTF32 format. If you know you&#39;re only getting ascii, then you can just do <br />string += (char)event-&gt;keybard.unichar .</p><p><a href="http://www.liballeg.org/a5docs/refman/events.html#allegro_event_key_char">http://www.liballeg.org/a5docs/refman/events.html#allegro_event_key_char</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Thu, 22 Dec 2011 21:28:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>&quot;<b>torhu:</b><br />You can use ALLEGRO_EVENT_KEY_CHAR, the unichar field contains the character that the user typed. If he holds down Shift and presses the A key, event.keyboard.unichar will be &#39;A&#39;, etc.&quot;</p><p>Could you please give an example of code? And what data type of variable should I use to store input characters?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Dvornik)</author>
		<pubDate>Thu, 22 Dec 2011 21:59:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>jmasterx&#39;s trick will work for ASCII and Latin-1 strings, but you could also do it roughly like this:</p><p>First:<br /><span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_USTR"><span class="a">ALLEGRO_USTR</span></a> <span class="k3">*</span>input <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_ustr_new"><span class="a">al_ustr_new</span></a><span class="k2">(</span><span class="s">""</span><span class="k2">)</span><span class="k2">;</span></span></p><p>Then, in your event loop:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">case</span> ALLEGRO_EVENT_KEY_CHAR: <span class="k2">{</span>
    <span class="k1">int</span> unichar <span class="k3">=</span> event.keyboard.unichar<span class="k2">;</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>
        <a href="http://www.allegro.cc/manual/al_ustr_append_chr"><span class="a">al_ustr_append_chr</span></a><span class="k2">(</span>input, unichar<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">break</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

And when you&#39;re done with the string:<br /><span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_free"><span class="a">al_ustr_free</span></a><span class="k2">(</span>input<span class="k2">)</span><span class="k2">;</span></span></p><p>If you want just one character at a time instead of the whole string, you can use <span class="source-code"><a href="http://www.allegro.cc/manual/al_utf8_encode"><span class="a">al_utf8_encode</span></a></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Thu, 22 Dec 2011 22:46:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>to <b>torhu</b></p><p>Thanks a lot for your advice!</p><p>I&#39;ll try it later. And one more question: if I need to delete char from word how should I write code?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Andrew Dvornik)</author>
		<pubDate>Thu, 22 Dec 2011 22:52:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>At first sight in the manual, I&#39;d say: <span class="source-code"><a href="http://www.allegro.cc/manual/al_ustr_truncate"><span class="a">al_ustr_truncate</span></a><span class="k2">(</span> ... <span class="k2">)</span></span><br />See the rest of manual to get current string length etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 22 Dec 2011 23:06:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Instead of using the manual on this site, you should use <a href="http://alleg.sourceforge.net/a5docs/5.0.5/utf8.html">this one</a>, which makes it a a bit easier to find what you&#39;re looking for by just browsing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Thu, 22 Dec 2011 23:24:18 +0000</pubDate>
	</item>
</rss>
