Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


SetWindowsHookEx Keyboard Hook

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sun Nov 09, 2008 10:07 pm    Post subject: SetWindowsHookEx Keyboard Hook Reply with quote

I'm having some troubles with this Keyboard Hook.dll
Code:
#include "windows.h"

HHOOK hHOOK = NULL;
unsigned char Signature[] = { VK_F1, VK_F2, VK_F3, VK_F4, VK_SPACE };

LRESULT CALLBACK CallBack(
                              int nCode,
                              WPARAM wParam,
                              LPARAM lParam)
{
   int Index = 0;
   if ( nCode == HC_ACTION )
   {
      unsigned char* Keys = new unsigned char[sizeof(Signature)];
      if (Index<4)
         *(unsigned char*)Keys[Index] = (unsigned char)wParam;
      if (Index==4)
         if (!memcmp(&Signature, Keys, Index))
         {
            Index = 0;
            MessageBox(NULL, "test", "test", MB_OK);
         }
      ZeroMemory(Keys, sizeof(Keys));
      Index++;
      delete(Keys);
   }
   return CallNextHookEx( hHOOK, nCode, wParam, lParam );   
}


BOOL APIENTRY DllMain( HINSTANCE hInstance,
                  DWORD ul_reason_for_call,
                  LPVOID lpReserved )
{
   switch( ul_reason_for_call )
   {
      case DLL_PROCESS_ATTACH:
         hHOOK = SetWindowsHookEx( WH_KEYBOARD, (HOOKPROC)CallBack, hInstance, 0 );
         break;
      case DLL_PROCESS_DETACH:
         UnhookWindowsHookEx( hHOOK );
         break;
   }
}


I created a program just to load the dll into itself. Doesn't that mean this hook to apply to that program?

Help please Embarassed

_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Nov 09, 2008 10:26 pm    Post subject: Reply with quote

What exactly are you attempting to do?

Code:

   int Index = 0;
   if ( nCode == HC_ACTION )
   {
      unsigned char* Keys = new unsigned char[sizeof(Signature)];
      if (Index<4)
         *(unsigned char*)Keys[Index] = (unsigned char)wParam;


This will always occur; Index will equal 0, no matter what.

Did you mean to make it static?

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sun Nov 09, 2008 10:33 pm    Post subject: Reply with quote

Whoops, no I didn't mean to make it static. But I still don't know how I could get it working. I tried removing the if(Index<4). I honestly don't know.
_________________
Blog

Quote:
Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that
Back to top
View user's profile Send private message MSN Messenger
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Mon Nov 10, 2008 2:11 am    Post subject: Reply with quote

Well for starters, DllMain is not returning any value.. when you call LoadLibrary() the system will immediately unload the dll.

Code:
BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
   switch (dwReason)
   {
   case DLL_PROCESS_ATTACH:
      hHOOK = SetWindowsHookEx( WH_KEYBOARD, (HOOKPROC)CallBack, hInstance, 0 );
      return TRUE;

   case DLL_PROCESS_DETACH:
      UnhookWindowsHookEx( hHOOK );
      return TRUE;
   }
   return TRUE;
}


The rest of your code is a mess to look at, what are you trying to do? Global hotkeys for VK_F1, VK_F2, VK_F3, etc? Here is a simple example,

Code:
LRESULT CALLBACK CallBack(int nCode, WPARAM wParam, LPARAM lParam)
{
   if (nCode < 0) // do not process message
      return CallNextHookEx( hHOOK, nCode, wParam, lParam );
   
   if (nCode == HC_ACTION)
   {
      bool bKeyDown = (HIWORD(lParam) & KF_UP) == 0;

      switch (wParam)
      {
      case VK_F1:
         if (bKeyDown) {
            MessageBox(NULL, "F1 down", "", MB_OK);
         } else {
            MessageBox(NULL, "F1 up", "", MB_OK);
         }
         break;
      }
   }

   return CallNextHookEx( hHOOK, nCode, wParam, lParam );   
}

Ideally you should pass the message to your main window and handle the logic there.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites