Solved

disable mouse buttons

Posted on 1998-12-11
11
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month6 days, 1 hour left to enroll

627 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