MadCodeHook global mouse/keyboard hook demo code, please

Hi, a newbie question here.

Does anyone have any MadCodeHook global keyboard/mouse hook demos laying around?

Basically, I need a demo of how to hook the mouse to get the mouse pointer position and hook the keyboard to get the current key that is being pressed (I need to hook all the keys, not just a-z).

The demos that Madshi has are way over my head.  

Thanks,

DevilDuck
devilduckAsked:
Who is Participating?
 
Slick812Commented:
hello devilduck, , I have done a little with the MadCodeHook, , but the MadCodeHook is a special and complex (compared to the usuall API), and if you are without deep API and code knowlage you can crash the whole system. . . I would not even think about using it unless I had a special hard to do problem. .

I would ask you, why don't you use the API  GetCursorPos( ) function to get the cursor position (mouse pointer is not exactly a programming term). . . also you can get the key being pressed with the standard API Key Hook, but I do not think there may be any API functions you can "Hook" with MadCodeHook to get the cursor pos or the current key that is being pressed. .  which API functions would you hook for that sort of thing, I do not think that the term "Hook" in the  MadCodeHook, is the same sort of meaning as the "Hook" of the API  SetWindowsHookEx( ), , , but I could be wrong about how I understand your question
0
 
Kyle FosterCEOCommented:
Here is a simple mousehook dll and test application that I downloaded from somewhere.  Not sure where.

www.certss.com\Downloads\ExpertExchange\MouseSystemHook.zip

This is a system wide global hook.  Is that what you are looking for?
0
 
devilduckAuthor Commented:
Thanks for the reply, kfoster11.  

I am looking for demo code using MadCodeHook specifically.  

Thanks,

DD
0
 
Scay7Commented:
Few things that youll need to do first though

1. first go to " http://www.madcodehook.com " and download the (madcollection.exe)
2. Create a dll using this code :

*****************************************************************
library TPHook;

uses Windows, madRemote, madCodeHook, madStrings;

var TerminateProcessNext : function (processHandle, exitCode: dword) : bool; stdcall;

function ThisIsOurProcess(processHandle: dword) : boolean;
var pid   : dword;
    arrCh : array [0..MAX_PATH] of char;
begin
  pid := ProcessHandleToId(processHandle);
  result := (pid <> 0) and ProcessIdToFileName(pid, arrCh) and
            (PosText('OurApplication.exe', arrCh) > 0);         <----*** very important use you own    
                                                                                                 application name
end;

function TerminateProcessCallback(processHandle, exitCode: dword) : bool; stdcall;
begin
  if ThisIsOurProcess(processHandle) then begin
    result := false;
    SetLastError(ERROR_ACCESS_DENIED);
  end else
    result := TerminateProcessNext(processHandle, exitCode);
end;

begin
  HookAPI('kernel32.dll', 'TerminateProcess', @TerminateProcessCallback, @TerminateProcessNext);
end.
*****************************************************************

rename that dll to "TPHook.dll"

3. in your program under uses "madcodehook"
4. in your project should look something like this :

program ***; // this is your program name that the dll will hook

uses
  Forms,windows, madcodehook,

{$R *.RES}

begin

  InjectLibrary(ALL_SESSIONS or SYSTEM_PROCESSES, 'TPHook.dll');
  Application.Title := '';
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

5. Last with the madcodehook in your unit1 uses (or whatever) you have to Uninject the dll something like :

procedure TForm1.Exit2Click(Sender: TObject);
begin
close;
UninjectLibrary(ALL_SESSIONS or SYSTEM_PROCESSES, 'TPHook.dll');
end;

So that if you call close from the program it self then only can you exit the program, otherwise if someone tries to end task it it wont allow it so long ass the DLL is hooked into the program...

Peace Scay7
0
 
Scay7Commented:
Oh dear me in my haste i pasted the wrong thing... that hook is to trap the exe from being end tasked... sowwie
please ignore that post...

Pease scay7

Sorry...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.