Solved

disable mouse buttons

Posted on 1998-12-11
11
148 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
searching for DavidI's "Mobile Summer School download" 3 128
delphi exception 7 63
Delphi inherited method 6 63
Firemonkey webbrowser scrollbars ? 1 29
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

21 Experts available now in Live!

Get 1:1 Help Now