Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

MadCodeHook global mouse/keyboard hook demo code, please

Posted on 2006-05-30
5
Medium Priority
?
939 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:devilduck
5 Comments
 
LVL 7

Expert Comment

by:kfoster11
ID: 16794626
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
 

Author Comment

by:devilduck
ID: 16794653
Thanks for the reply, kfoster11.  

I am looking for demo code using MadCodeHook specifically.  

Thanks,

DD
0
 
LVL 35

Accepted Solution

by:
Slick812 earned 2000 total points
ID: 16794843
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
 
LVL 5

Expert Comment

by:Scay7
ID: 16801996
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
 
LVL 5

Expert Comment

by:Scay7
ID: 16802077
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question