Solved

disable mouse buttons

Posted on 1998-12-11
11
146 Views
Last Modified: 2010-04-04
I would like to write an app that would run on a win9x machine and be capable of system wide left or right (each one individually) mouse button clicks.

I know from some research that i need to use hooks thus requiring me to use a dll. right? Ive never made a dll or used hooks. please help.  some source would be a great help.
thanx
0
Comment
Question by:joesmith69
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1350701
Hi joesmith69,

Here is an example, hope it still works. Try it out

Building Mouse Hooks

From: David Ullrich <ullrich@math.okstate.edu>


--------------------------------------------------------------------------------

library Hookdemo;

uses

  Beeper in '\DELDEMOS\HOOKDEMO\BEEPER.PAS';


exports
       SetHook index 1,
       UnHookHook index 2,
       HookProc index 3;

begin
   HookedAlready:=False;
end.

--------------------------------------------------------------------------------

, where beeper.pas is like so:


--------------------------------------------------------------------------------

unit Beeper;

interface

uses Wintypes,Winprocs,Messages;

function SetHook:Boolean;export;
function UnHookHook:Boolean;export;
function HookProc(Code:integer; wParam: Word; lParam: Longint): Longint;export;

var HookedAlready:Boolean;

implementation

var
   ourHook:HHook;


function SetHook:Boolean;
begin
if HookedAlready then exit;
ourHook:=SetWindowsHookEx(WH_MOUSE,HookProc,HInstance,0);
HookedAlready:=True;
end;

function UnHookHook:Boolean;
begin
UnHookWindowsHookEx(ourHook);
HookedAlready:=False;
end;

function HookProc(Code:integer; wParam: Word; lParam: Longint): Longint;
begin
   if (wParam=WM_LBUTTONDOWN) then MessageBeep(0);
   result:=CallNextHookEx(ourHook,Code,wParam,lParam);
end;

end.

--------------------------------------------------------------------------------

Now if you call the SetHook function from an application there's a beep everytime you press the left mouse button - this continues until you call the UnHookHook function. In an actual application you're supposed to call CallNextHookEx immediately and do nothing else if code < 0 .

Regards, Zif.
0
 

Author Comment

by:joesmith69
ID: 1350702
Zif,
When compiling it dies on:
ourHook:=SetWindowsHookEx(WH_MOUSE,HookProc,HInstance,0);
with the error:
incompatible types: calling conventions differ.
all the help says is:
The compiler has detected a difference between the declaration and use of a procedure.

huh? sorry the solution may be obvious but not to me. any ideas what the problem could be. if i remark out that line the thing compiles fine but thats where all the good stuff i want to do happens.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350703
I think if you change this from

function HookProc(Code:integer; wParam: Word; lParam: Longint): Longint;export;

to

function HookProc(Code:integer; wParam: Word; lParam: Longint): Longint;export; stdcall;

all will be well.

Cheers,

Raymond.

0
 

Author Comment

by:joesmith69
ID: 1350704
sorry to be so much trouble guys...
i changed the function as Raymond described & the compiler barfs @the same line still:                   right here
                                           |
                                           v
ourHook:=SetWindowsHookEx(WH_MOUSE,HookProc,HInstance,0);

and says incompatiable types: integer and word. i changed the following line from:
function HookProc(Code:integer;wParam:Word;lParam:Longint)
                  :Longint;export; stdcall;
to
function HookProc(Code:integer;wParam:integer;lParam:Longint)
                  :Longint;export; stdcall;

which got it to compile but it doesnt work when i call the sethook function. what am i missing??





0
 

Author Comment

by:joesmith69
ID: 1350705
that arrow was supposed to point between "hookproc" and "Hinstance" but it didnt quite work out the way i planned. sorry.

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 1350706
Hi Joe,

Zif's example was written for Delphi1/16bit windows. That's why there were so many problems. Here comes the 32bit version:

library mouseDll;

uses Windows,Messages;

var ourHook : HHook;

function HookProc(Code, wParam, lParam: integer) : integer; stdcall;
begin
  if (wParam=WM_LBUTTONDOWN) then MessageBeep(0);
  result:=CallNextHookEx(ourHook,Code,wParam,lParam);
end;

procedure SetHook;
begin
  if ourHook<>0 then exit;
  ourHook:=SetWindowsHookEx(WH_MOUSE,HookProc,GetModuleHandle('mouseDll'),0);
end;

procedure UnHookHook;
begin
  if ourHook=0 then exit;
  UnHookWindowsHookEx(ourHook);
  ourHook:=0;
end;

exports SetHook    index 1,
        UnhookHook index 2;

begin
  ourHook:=0;
end.

Regards, Madshi.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350707
Took the words right out of my mouth (it was obvious what the problem was after Joes clarfication!) I admit the export did look strange in my suggestion but didn't act on the hunch - oh well.

Cheers Madshi!

Raymond.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1350708
Thank you, Raymond...   :-)
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1350709
I see problem is solved already. See you guys!
0
 

Author Comment

by:joesmith69
ID: 1350710
well madshi thanks for the input, but that didnt work either.

it complied fine..... but again didnt do anything when calling the sethook and unhookhook..... but no matter...
i found a great component to do the trick @
ftp://ftp.uniovi.es/pub4/delphi/ftp/d30free/fngb2302.exe
thanks for all your input
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1350711
I'm sorry, Joe. You must have done something wrong. I tested it and it worked great!!!

Regards, Madshi.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now