Solved

disable mouse buttons

Posted on 1998-12-11
11
149 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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