<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Gedrückte Taste in String]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich habe eine Frage und zwar:</p>
<p>Wie kann ich einen Tastendruck in einen String umwandeln?<br />
Also, wenn jetzt das Fenster eine F1-KeyDown bekommt, soll in dem String F1 stehen. Hat die WinAPI dafür irgend eine Function?</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/220936/gedrückte-taste-in-string</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 08:05:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/220936.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 23 Aug 2008 08:34:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Gedrückte Taste in String on Sat, 23 Aug 2008 08:34:41 GMT]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich habe eine Frage und zwar:</p>
<p>Wie kann ich einen Tastendruck in einen String umwandeln?<br />
Also, wenn jetzt das Fenster eine F1-KeyDown bekommt, soll in dem String F1 stehen. Hat die WinAPI dafür irgend eine Function?</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1569943</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1569943</guid><dc:creator><![CDATA[Keyboard]]></dc:creator><pubDate>Sat, 23 Aug 2008 08:34:41 GMT</pubDate></item><item><title><![CDATA[Reply to Gedrückte Taste in String on Sat, 23 Aug 2008 10:08:51 GMT]]></title><description><![CDATA[<p>also erstmal, wenn du in einem MessageHandler auf eine WM_KEYDOWN nachricht reagierst:</p>
<p>Wenn du spezialtasten in den string kopieren willst, musst du das selbst machen, d.h wenn VK_F1 gedrückt wird fügst du dem string ein &quot;F1&quot; an/kopierst es darein</p>
<p>Wenn du Lexikalischen Input in den String kopieren willst, dann solltest du lieber auf die WM_CHAR oder WM_UNICHAR nachricht reagieren. der Zeichencode ist in wParam gespeichert. willst du UTF16 zeichen speichern, dann schau her:</p>
<pre><code class="language-cpp">// erstmal ohne ende copypasta, damit man utf32 in utf16 verwandlen kann
#define SURROGATE_PAIRS_HI_MIN  ((uint16_t)0xd800)
#define SURROGATE_PAIRS_HI_MAX  ((uint16_t)0xdbff)
#define SURROGATE_PAIRS_LO_MIN  ((uint16_t)0xdc00)
#define SURROGATE_PAIRS_LO_MAX  ((uint16_t)0xdfff)
#define SURROGATE_PAIRS_BIT_SZ  ((uint32_t)10)
#define SURROGATE_PAIRS_MASK    (((uint16_t)1 &lt;&lt; SURROGATE_PAIRS_BIT_SZ)-1)
#define IsSurrogatePairsHi(_h)  (SURROGATE_PAIRS_HI_MIN == \
                      ((uint16_t)(_h) &amp;~ (uint16_t)SURROGATE_PAIRS_MASK ))
#define IsSurrogatePairsLo(_l)  (SURROGATE_PAIRS_LO_MIN == \
                      ((uint16_t)(_l) &amp;~ (uint16_t)SURROGATE_PAIRS_MASK ))
#define utf16_utf32(_h,_l) \
  (((((uint32_t)_h) &amp; SURROGATE_PAIRS_MASK) &lt;&lt; SURROGATE_PAIRS_BIT_SZ) + \
   (( (uint32_t)_l) &amp; SURROGATE_PAIRS_MASK) +				\
   (  (uint32_t)0xffff))

#define utf32_utf16(_wc32,_wcs)     \
{									\
    if(0xffff &lt; (uint32_t)_wc32)    \
    {					            \
        (_wcs)[0] = ((uint32_t)_wc32 &gt;&gt; SURROGATE_PAIRS_BIT_SZ ) +  \
        SURROGATE_PAIRS_HI_MIN ;					                \
        (_wcs)[1] = ((uint32_t)_wc32 &amp; SURROGATE_PAIRS_MASK ) +		\
        SURROGATE_PAIRS_LO_MIN ;					                \
        (_wcs)[2] = 0;							                    \
    }                               \
    else                            \
    {								\
        (_wcs)[0] = ((uint32_t)_wc32) &amp; 0xffff;				        \
        (_wcs)[1] = 0;							                    \
    }									                            \
}
...
	case WM_UNICHAR:
	{
	    if(wParam == UNICODE_NOCHAR) return TRUE;
        if((lParam &amp; 0x80000000) == 0)
        {
            wchar_t buf[3];
            utf32_utf16(wParam,buf);
            // hier kannst du deinem string den Buffer buf anfügen/ ihn hineinkopieren
        }
        return 0;
	}
</code></pre>
<p>bei WM_CHAR fällt das etwas einfacher aus:</p>
<pre><code class="language-cpp">case WM_CHAR:
	{
        if((lParam &amp; 0x80000000) == 0)
        {
            char buf = (char)(wParam &amp; 0xff);
            // hier kannst du deinem string den Buffer buf anfügen/ ihn hineinkopieren
        }
</code></pre>
<p>wenn du den Status des Keys mit GetAsyncKeyState prüfst, musst du dasselbe machen, wie auf reaktion auf WM_KEYDOWN - selber einen String anfügen/kopieren</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1569986</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1569986</guid><dc:creator><![CDATA[Azrael* il Meraz]]></dc:creator><pubDate>Sat, 23 Aug 2008 10:08:51 GMT</pubDate></item></channel></rss>