<?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[Maus Hook in DLL funzt nicht]]></title><description><![CDATA[<p>Hallo !<br />
Ich möchte für einen 3-D Shooter einen No-Recoil-Hook schreiben.<br />
Das soll folgendermassen funktionieren.<br />
Beim drücken (und beim gedrückthalten der linken Maustaste) soll sich die Maus nach unten bewegen.<br />
Im Windows funktioniert das ja auch wunderbar aber im Spiel geht das mit der Maus nichtmehr ?? Hab leider keine Ahnung wieso <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Hier meine DLL :</p>
<pre><code class="language-cpp">// InputHook.cpp : Defines the initialization routines for the DLL.
//

#include &quot;stdafx.h&quot;
#include &lt;Winuser.h&gt;
#include &lt;windows.h&gt;
#include &quot;InputHook.h&quot;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#pragma data_seg (&quot;Shared&quot;) 
HWND hWindow = NULL ; 
int oldMouseState = 0;
long msecs = 0;
long sleeptime = 5;
#pragma data_seg () 

// Weise den Compilern, den Abschnitt Shared als lesbar, 
// beschreibbar und zur gemeinsamen Verwendung zu deklarieren - &quot;RSW&quot;. 
#pragma comment (linker, &quot;/section:Shared,RWS&quot;)

HINSTANCE hThisDLL;
static HHOOK hHookKeyboard = NULL;
static HHOOK hHookMouse = NULL;
int newMouseState;
int myTimer;

BEGIN_MESSAGE_MAP(CInputHookApp, CWinApp)
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////////////
LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(int hook_code, WPARAM virtual_key_code, LPARAM keystroke_message_info)
{
	if ((hook_code == HC_ACTION) &amp;&amp; (GetKeyEventType(keystroke_message_info) == 0)) //DOWN
		switch(virtual_key_code) //defined in winuser.h
		{
		case VK_LEFT:
			keybd_event( 0x5A, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );// Simulate a key press
			break;
		case VK_RIGHT:
			keybd_event( 0x55, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );// Simulate a key press
			break;
		}
	else if ((hook_code == HC_ACTION) &amp;&amp; (GetKeyEventType(keystroke_message_info) == 1))	 //UP
		switch(virtual_key_code) 
		{
		case VK_LEFT:
			keybd_event( 0x5A, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
			break;
		case VK_RIGHT:
			keybd_event( 0x55, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
			break;
		}
	else if ((hook_code == HC_ACTION) &amp;&amp; (GetKeyEventType(keystroke_message_info) == 2)) //REPEAT
	{
		switch(virtual_key_code) //defined in winuser.h
		{
		case VK_LEFT:
			keybd_event( 0x5A, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );// Simulate a key press
			break;
		case VK_RIGHT:
			keybd_event( 0x55, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );// Simulate a key press
			break;
		}
	}
return CallNextHookEx (hHookKeyboard,hook_code, virtual_key_code, keystroke_message_info );
}

LRESULT __declspec(dllexport)__stdcall CALLBACK LowLevelMouseProc(int hook_code, WPARAM message_identifier, LPARAM mouse_coordinates)
{

	if (hook_code == HC_ACTION)
	{
		newMouseState = GetAsyncKeyState(VK_LBUTTON);
		if (newMouseState == -32767 &amp;&amp; oldMouseState == 0) //DOWN
		{
			oldMouseState = -32767;
			msecs = 0;
		}
		if (newMouseState == 0 &amp;&amp; oldMouseState == -32767) //UP
		{
			oldMouseState = 0;
			mouse_event(MOUSEEVENTF_MOVE,0,5,1,1);
		}
	}

return CallNextHookEx (hHookMouse,hook_code, message_identifier, mouse_coordinates);
}

BOOL __declspec(dllexport)__stdcall InstallHookKeyboard()
{
	hHookKeyboard = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hThisDLL,0);
	myTimer = SetTimer(NULL, NULL, 10, TimerProc);
	return TRUE;
}

BOOL __declspec(dllexport)__stdcall InstallHookMouse()
{
	hHookMouse = SetWindowsHookEx(WH_MOUSE,(HOOKPROC)LowLevelMouseProc,hThisDLL,0);
	return TRUE;
}

BOOL __declspec(dllexport)__stdcall  UninstallHookKeyboard()
{
	KillTimer(NULL,myTimer);
     return UnhookWindowsHookEx(hHookKeyboard);
}

BOOL __declspec(dllexport)__stdcall  UninstallHookMouse()
{
     return UnhookWindowsHookEx(hHookMouse);
} 

////////////////////////////////////////////////////////////////////////////////////
// CInputHookApp construction
CInputHookApp::CInputHookApp(){}
// The one and only CInputHookApp object
CInputHookApp theApp;
// CInputHookApp initialization

BOOL CInputHookApp::InitInstance()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	hThisDLL=AfxGetInstanceHandle();
	return TRUE;
}
BOOL CInputHookApp::ExitInstance()
{
	return TRUE;
}

int GetKeyEventType(LPARAM lParam)
{
	// Reference: WM_KEYDOWN on MSDN
	if (lParam &amp; 0x80000000) // check bit 31 for up/down
		return 1; //UP
	else
	{
		if (lParam &amp; 0x40000000) // check bit 30 for previous up/down
			return 2; // It was pressed down before this key-down event, so it's a key-repeat for sure
		else
			return 0; //DOWN
	}
}

void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
	msecs++;
	if(msecs &gt;= sleeptime)
	{
		if (GetAsyncKeyState(VK_LBUTTON) != 0 &amp;&amp; oldMouseState != 0)
				mouse_event(MOUSEEVENTF_MOVE,0,5,1,1);
		msecs = 0;
	}
}
</code></pre>
<p>Und hier das wichtige aus dem Hauptprogramm:</p>
<pre><code class="language-cpp">void CInstallhookDlg::OnOk() 
{
static HINSTANCE hinstDLL; 
typedef BOOL (CALLBACK *inshook)(); 
inshook instkbhook;
inshook instmhook;
hinstDLL = LoadLibrary((LPCTSTR) &quot;InputHook.dll&quot;); 
instkbhook = (inshook)GetProcAddress(hinstDLL, &quot;InstallHookKeyboard&quot;);
instmhook = (inshook)GetProcAddress(hinstDLL, &quot;InstallHookMouse&quot;); 
instkbhook();
instmhook();
}
</code></pre>
<p>Kann mir da jemand weiterhelfen ??</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/78808/maus-hook-in-dll-funzt-nicht</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 13:09:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/78808.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Jul 2004 14:58:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Maus Hook in DLL funzt nicht on Mon, 05 Jul 2004 14:58:01 GMT]]></title><description><![CDATA[<p>Hallo !<br />
Ich möchte für einen 3-D Shooter einen No-Recoil-Hook schreiben.<br />
Das soll folgendermassen funktionieren.<br />
Beim drücken (und beim gedrückthalten der linken Maustaste) soll sich die Maus nach unten bewegen.<br />
Im Windows funktioniert das ja auch wunderbar aber im Spiel geht das mit der Maus nichtmehr ?? Hab leider keine Ahnung wieso <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Hier meine DLL :</p>
<pre><code class="language-cpp">// InputHook.cpp : Defines the initialization routines for the DLL.
//

#include &quot;stdafx.h&quot;
#include &lt;Winuser.h&gt;
#include &lt;windows.h&gt;
#include &quot;InputHook.h&quot;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#pragma data_seg (&quot;Shared&quot;) 
HWND hWindow = NULL ; 
int oldMouseState = 0;
long msecs = 0;
long sleeptime = 5;
#pragma data_seg () 

// Weise den Compilern, den Abschnitt Shared als lesbar, 
// beschreibbar und zur gemeinsamen Verwendung zu deklarieren - &quot;RSW&quot;. 
#pragma comment (linker, &quot;/section:Shared,RWS&quot;)

HINSTANCE hThisDLL;
static HHOOK hHookKeyboard = NULL;
static HHOOK hHookMouse = NULL;
int newMouseState;
int myTimer;

BEGIN_MESSAGE_MAP(CInputHookApp, CWinApp)
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////////////
LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(int hook_code, WPARAM virtual_key_code, LPARAM keystroke_message_info)
{
	if ((hook_code == HC_ACTION) &amp;&amp; (GetKeyEventType(keystroke_message_info) == 0)) //DOWN
		switch(virtual_key_code) //defined in winuser.h
		{
		case VK_LEFT:
			keybd_event( 0x5A, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );// Simulate a key press
			break;
		case VK_RIGHT:
			keybd_event( 0x55, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );// Simulate a key press
			break;
		}
	else if ((hook_code == HC_ACTION) &amp;&amp; (GetKeyEventType(keystroke_message_info) == 1))	 //UP
		switch(virtual_key_code) 
		{
		case VK_LEFT:
			keybd_event( 0x5A, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
			break;
		case VK_RIGHT:
			keybd_event( 0x55, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
			break;
		}
	else if ((hook_code == HC_ACTION) &amp;&amp; (GetKeyEventType(keystroke_message_info) == 2)) //REPEAT
	{
		switch(virtual_key_code) //defined in winuser.h
		{
		case VK_LEFT:
			keybd_event( 0x5A, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );// Simulate a key press
			break;
		case VK_RIGHT:
			keybd_event( 0x55, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );// Simulate a key press
			break;
		}
	}
return CallNextHookEx (hHookKeyboard,hook_code, virtual_key_code, keystroke_message_info );
}

LRESULT __declspec(dllexport)__stdcall CALLBACK LowLevelMouseProc(int hook_code, WPARAM message_identifier, LPARAM mouse_coordinates)
{

	if (hook_code == HC_ACTION)
	{
		newMouseState = GetAsyncKeyState(VK_LBUTTON);
		if (newMouseState == -32767 &amp;&amp; oldMouseState == 0) //DOWN
		{
			oldMouseState = -32767;
			msecs = 0;
		}
		if (newMouseState == 0 &amp;&amp; oldMouseState == -32767) //UP
		{
			oldMouseState = 0;
			mouse_event(MOUSEEVENTF_MOVE,0,5,1,1);
		}
	}

return CallNextHookEx (hHookMouse,hook_code, message_identifier, mouse_coordinates);
}

BOOL __declspec(dllexport)__stdcall InstallHookKeyboard()
{
	hHookKeyboard = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hThisDLL,0);
	myTimer = SetTimer(NULL, NULL, 10, TimerProc);
	return TRUE;
}

BOOL __declspec(dllexport)__stdcall InstallHookMouse()
{
	hHookMouse = SetWindowsHookEx(WH_MOUSE,(HOOKPROC)LowLevelMouseProc,hThisDLL,0);
	return TRUE;
}

BOOL __declspec(dllexport)__stdcall  UninstallHookKeyboard()
{
	KillTimer(NULL,myTimer);
     return UnhookWindowsHookEx(hHookKeyboard);
}

BOOL __declspec(dllexport)__stdcall  UninstallHookMouse()
{
     return UnhookWindowsHookEx(hHookMouse);
} 

////////////////////////////////////////////////////////////////////////////////////
// CInputHookApp construction
CInputHookApp::CInputHookApp(){}
// The one and only CInputHookApp object
CInputHookApp theApp;
// CInputHookApp initialization

BOOL CInputHookApp::InitInstance()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	hThisDLL=AfxGetInstanceHandle();
	return TRUE;
}
BOOL CInputHookApp::ExitInstance()
{
	return TRUE;
}

int GetKeyEventType(LPARAM lParam)
{
	// Reference: WM_KEYDOWN on MSDN
	if (lParam &amp; 0x80000000) // check bit 31 for up/down
		return 1; //UP
	else
	{
		if (lParam &amp; 0x40000000) // check bit 30 for previous up/down
			return 2; // It was pressed down before this key-down event, so it's a key-repeat for sure
		else
			return 0; //DOWN
	}
}

void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
	msecs++;
	if(msecs &gt;= sleeptime)
	{
		if (GetAsyncKeyState(VK_LBUTTON) != 0 &amp;&amp; oldMouseState != 0)
				mouse_event(MOUSEEVENTF_MOVE,0,5,1,1);
		msecs = 0;
	}
}
</code></pre>
<p>Und hier das wichtige aus dem Hauptprogramm:</p>
<pre><code class="language-cpp">void CInstallhookDlg::OnOk() 
{
static HINSTANCE hinstDLL; 
typedef BOOL (CALLBACK *inshook)(); 
inshook instkbhook;
inshook instmhook;
hinstDLL = LoadLibrary((LPCTSTR) &quot;InputHook.dll&quot;); 
instkbhook = (inshook)GetProcAddress(hinstDLL, &quot;InstallHookKeyboard&quot;);
instmhook = (inshook)GetProcAddress(hinstDLL, &quot;InstallHookMouse&quot;); 
instkbhook();
instmhook();
}
</code></pre>
<p>Kann mir da jemand weiterhelfen ??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/553694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/553694</guid><dc:creator><![CDATA[chr1scht]]></dc:creator><pubDate>Mon, 05 Jul 2004 14:58:01 GMT</pubDate></item><item><title><![CDATA[Reply to Maus Hook in DLL funzt nicht on Mon, 05 Jul 2004 15:54:33 GMT]]></title><description><![CDATA[<p>Dein Subject klingt so, als würde es nur in einer DLL nicht funktionieren, sonst aber schon. Das ist wahrscheinlich nicht der Fall.</p>
<p>Ich vermute mal, dass das Spiel DirectInput verwendet und dass dieses jegliche Hooks einfach ignoriert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/553747</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/553747</guid><dc:creator><![CDATA[Ringding]]></dc:creator><pubDate>Mon, 05 Jul 2004 15:54:33 GMT</pubDate></item><item><title><![CDATA[Reply to Maus Hook in DLL funzt nicht on Mon, 05 Jul 2004 16:51:44 GMT]]></title><description><![CDATA[<p>Mit dem billigsten Visual Basic Code funktioniert es auf jeden Fall.<br />
Ich hab gedacht ich machs halt so wie ichs überall gelesen hab in ner DLL damit es schön sauber ist und funktioniert aber Pustekuchen GEHT NET <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /><br />
Wenn ich die Api Funktionen direkt im Programm Aufruf und zwar mit dem guten alten VB dann klappts einwandfrei trotz Direct Input ^^</p>
<p>echt rofl ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/553801</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/553801</guid><dc:creator><![CDATA[chr1scht]]></dc:creator><pubDate>Mon, 05 Jul 2004 16:51:44 GMT</pubDate></item><item><title><![CDATA[Reply to Maus Hook in DLL funzt nicht on Tue, 06 Jul 2004 14:20:37 GMT]]></title><description><![CDATA[<p>versuchs mal mit sendinput oder so anstatt mit keyboadevent<br />
dann musst du den fensterhandle des programms herausfinden (IS_VISIBLE)<br />
und so kannst du es dann direkt zum programm senden</p>
]]></description><link>https://www.c-plusplus.net/forum/post/554525</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/554525</guid><dc:creator><![CDATA[reima]]></dc:creator><pubDate>Tue, 06 Jul 2004 14:20:37 GMT</pubDate></item><item><title><![CDATA[Reply to Maus Hook in DLL funzt nicht on Tue, 06 Jul 2004 17:12:15 GMT]]></title><description><![CDATA[<p>Hab folgendes probiert :</p>
<pre><code class="language-cpp">HWND TO = GetActiveWindow();
SendMessage(TO,0,message_identifier,mouse_coordinates);
</code></pre>
<p>Leider gehts immer noch nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Wenn ich im Fenstermodus bin dann funktioniert es auch im Spielfenster aber sobal das Spiel bzw. eine Map geladen ist und das Spiel losgeht funktioniert es nichtmehr.<br />
Aber das war ja vorher schon so</p>
<p>Greetz</p>
]]></description><link>https://www.c-plusplus.net/forum/post/554691</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/554691</guid><dc:creator><![CDATA[chr1scht]]></dc:creator><pubDate>Tue, 06 Jul 2004 17:12:15 GMT</pubDate></item><item><title><![CDATA[Reply to Maus Hook in DLL funzt nicht on Wed, 07 Jul 2004 00:06:22 GMT]]></title><description><![CDATA[<p>Hab jetzt nen LowLevelMouseHook genommen dann gings <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
Greetz</p>
]]></description><link>https://www.c-plusplus.net/forum/post/554899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/554899</guid><dc:creator><![CDATA[chr1scht]]></dc:creator><pubDate>Wed, 07 Jul 2004 00:06:22 GMT</pubDate></item></channel></rss>