<?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[Global Tasten abfragen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich verzweifle grade beim Hooken vom Keyboard.<br />
Ich benutze SetWindowsHookEx und gebe eine Funktion aus einer DLL an.<br />
Ausserdem gebe ich der DLL über eine andere Funktion ein HWND an das das KeyboardProc eine Message senden soll.</p>
<p>Das hooken funktioniert richtig wenn mein eigenes Fenster foreground ist.<br />
Auch scheint der KeyboardProc immer aufgerufen zu werden. Nur leider funktioniert dann das senden von Messages an mein Fenster nicht, wenn es nicht foreground ist.</p>
<p>Hier mein CODE für den Hook und die DLL:</p>
<pre><code>int StartKeyLogger(LPCTSTR strPath, HWND hWnd)
{
	g_hDLL = LoadLibrary(strPath); 
	if (!g_hDLL) return -1;

	g_hProc = (HOOKPROC)GetProcAddress(g_hDLL, &quot;KeyboardProc&quot;); 
	if (!g_hProc) return -2;

	g_hHook = SetWindowsHookEx(WH_KEYBOARD, g_hProc, g_hDLL, 0);
	if (!g_hHook) return -3;

	g_hSet = (SETHWND)GetProcAddress(g_hDLL, &quot;SetWnd&quot;); 
	if (!g_hSet) return -4; 

	g_hSet(hWnd);

	return 1;
};
</code></pre>
<p>Und das hier ist der Inhalt meiner DLL:</p>
<pre><code>#include &lt;windows.h&gt;
#define EOF (-1)

#ifdef __cplusplus    // If used by C++ code, 
extern &quot;C&quot; {          // we need to export the C interface
#endif

HWND g_hWnd = NULL;

__declspec(dllexport) LRESULT KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
	if ((nCode == HC_ACTION) &amp;&amp; (wParam == 'I') &amp;&amp; (GetAsyncKeyState(VK_CONTROL))) {	
		PostMessage(g_hWnd, 501, (WPARAM)GetForegroundWindow(), 0);
	};
	return CallNextHookEx(0, nCode, wParam, lParam);
};

__declspec(dllexport) void SetWnd(HWND hWnd) {
	g_hWnd = hWnd;
};

#ifdef __cplusplus
}
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/130690/global-tasten-abfragen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Jul 2026 15:42:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/130690.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Dec 2005 10:36:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Global Tasten abfragen on Mon, 26 Dec 2005 10:41:37 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich verzweifle grade beim Hooken vom Keyboard.<br />
Ich benutze SetWindowsHookEx und gebe eine Funktion aus einer DLL an.<br />
Ausserdem gebe ich der DLL über eine andere Funktion ein HWND an das das KeyboardProc eine Message senden soll.</p>
<p>Das hooken funktioniert richtig wenn mein eigenes Fenster foreground ist.<br />
Auch scheint der KeyboardProc immer aufgerufen zu werden. Nur leider funktioniert dann das senden von Messages an mein Fenster nicht, wenn es nicht foreground ist.</p>
<p>Hier mein CODE für den Hook und die DLL:</p>
<pre><code>int StartKeyLogger(LPCTSTR strPath, HWND hWnd)
{
	g_hDLL = LoadLibrary(strPath); 
	if (!g_hDLL) return -1;

	g_hProc = (HOOKPROC)GetProcAddress(g_hDLL, &quot;KeyboardProc&quot;); 
	if (!g_hProc) return -2;

	g_hHook = SetWindowsHookEx(WH_KEYBOARD, g_hProc, g_hDLL, 0);
	if (!g_hHook) return -3;

	g_hSet = (SETHWND)GetProcAddress(g_hDLL, &quot;SetWnd&quot;); 
	if (!g_hSet) return -4; 

	g_hSet(hWnd);

	return 1;
};
</code></pre>
<p>Und das hier ist der Inhalt meiner DLL:</p>
<pre><code>#include &lt;windows.h&gt;
#define EOF (-1)

#ifdef __cplusplus    // If used by C++ code, 
extern &quot;C&quot; {          // we need to export the C interface
#endif

HWND g_hWnd = NULL;

__declspec(dllexport) LRESULT KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
	if ((nCode == HC_ACTION) &amp;&amp; (wParam == 'I') &amp;&amp; (GetAsyncKeyState(VK_CONTROL))) {	
		PostMessage(g_hWnd, 501, (WPARAM)GetForegroundWindow(), 0);
	};
	return CallNextHookEx(0, nCode, wParam, lParam);
};

__declspec(dllexport) void SetWnd(HWND hWnd) {
	g_hWnd = hWnd;
};

#ifdef __cplusplus
}
#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/950061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950061</guid><dc:creator><![CDATA[neq]]></dc:creator><pubDate>Mon, 26 Dec 2005 10:41:37 GMT</pubDate></item><item><title><![CDATA[Reply to Global Tasten abfragen on Mon, 26 Dec 2005 13:40:56 GMT]]></title><description><![CDATA[<p>Es gibt diverse Beispiele wie man sowas (erfolgreich) macht...<br />
Das g_hWnd ist in jedem Prozess eine lokale Variable...<br />
Schau Dir doch mal bitte die Beispiele an (<a href="http://codeproject.com" rel="nofollow">codeproject.com</a>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/950204</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/950204</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Mon, 26 Dec 2005 13:40:56 GMT</pubDate></item></channel></rss>