Solved

KeyHook.dll

Posted on 1998-12-25
1
207 Views
Last Modified: 2010-04-04
I was playing around with KeyHook.dll project (KeyHook.zip archive).
It counts the keypresses. I was trying to make it show me which key was pressed, but couldn't find out how...
Any tips?
0
Comment
Question by:PsychoFox
1 Comment
 
LVL 20

Accepted Solution

by:
Madshi earned 20 total points
ID: 1352963
Hmmm. I found no KeyHook.* on my hard disk. But I guess it uses SetWindowsHookEx.
So the hook callback function should look like this:


function KeybHookProc(code: integer; wParam, lParam: integer) : integer; stdcall;
var down : boolean;
    ext  : boolean;
    alt  : boolean;
begin
  result:=0;
  if code<0 then begin
    result:=CallNextHookEx(MyHook,code,wParam,lParam);
    exit;
  end;
  down:=not odd(lParam shr 31); ext:=odd(lParam shr 24); alt:=odd(lParam shr 29);
  case wParam of
    ord('A')..ord('Z') : UserEvent(chr(wParam),down,false);
    ord('0')..ord('9') : UserEvent(chr(wParam),down,false);
    186          : UserEvent('Ü',      down,false);
    187          : UserEvent('+',      down,false);
    188          : UserEvent(',',      down,false);
    189          : UserEvent('-',      down,false);
    190          : UserEvent('.',      down,false);
    191          : UserEvent('#',      down,false);
    192          : UserEvent('Ö',      down,false);
    219          : UserEvent('ß',      down,false);
    220          : UserEvent('^',      down,false);
    221          : UserEvent('´',      down,false);
    222          : UserEvent('Ä',      down,false);
    226          : UserEvent('<',      down,false);
    VK_SPACE     : UserEvent(' ',      down,false);
    VK_TAB       : UserEvent('Tab',    down,false);
    VK_BACK      : UserEvent('Back',   down,true );
    VK_CAPITAL   : UserEvent('Caps',   down,true );
    VK_SHIFT     : begin UserEvent('%Sh.',   down,false); UserEvent('Sh.',  down,false) end;
    VK_CONTROL   : if ext then UserEvent('%Strg', down,false) else UserEvent('Strg', down,false);
    VK_MENU      : if ext then begin UserEvent('Strg',false,false); UserEvent('Alt Gr', down,false) end
                       else UserEvent('Alt',  down,false);
    VK_RETURN    : if ext then UserEvent('%Enter', down,false)
                       else begin  UserEvent('Ret1',   down,false);     UserEvent('Ret2', down,false) end;
    VK_ESCAPE    : UserEvent('Esc',    down,true );
    VK_F1        : UserEvent('F1',     down,true );
    VK_F2        : UserEvent('F2',     down,true );
    VK_F3        : UserEvent('F3',     down,true );
    VK_F4        : UserEvent('F4',     down,(not bNoClose) or (not alt));
    VK_F5        : UserEvent('F5',     down,true );
    VK_F6        : UserEvent('F6',     down,true );
    VK_F7        : UserEvent('F7',     down,true );
    VK_F8        : UserEvent('F8',     down,true );
    VK_F9        : UserEvent('F9',     down,true );
    VK_F10       : UserEvent('F10',    down,true );
    VK_F11       : UserEvent('F11',    down,true );
    VK_F12       : UserEvent('F12',    down,true );
    VK_SNAPSHOT  : UserEvent('Druck',  down,true );
    VK_SCROLL    : UserEvent('Rollen', down,true );
    VK_CANCEL    : UserEvent('Pause',  down,true );
    VK_PAUSE     : UserEvent('Pause',  down,true );
    VK_NUMLOCK   : UserEvent('%Num',   down,false);
    VK_NUMPAD0   : UserEvent('%0',     down,false);
    VK_NUMPAD1   : UserEvent('%1',     down,false);
    VK_NUMPAD2   : UserEvent('%2',     down,false);
    VK_NUMPAD3   : UserEvent('%3',     down,false);
    VK_NUMPAD4   : UserEvent('%4',     down,false);
    VK_NUMPAD5   : UserEvent('%5',     down,false);
    VK_NUMPAD6   : UserEvent('%6',     down,false);
    VK_NUMPAD7   : UserEvent('%7',     down,false);
    VK_NUMPAD8   : UserEvent('%8',     down,false);
    VK_NUMPAD9   : UserEvent('%9',     down,false);
    VK_CLEAR     : UserEvent('%5',     down,false);
    VK_DIVIDE    : UserEvent('%/',     down,false);
    VK_MULTIPLY  : UserEvent('%x',     down,false);
    VK_SUBTRACT  : UserEvent('%-',     down,false);
    VK_ADD       : UserEvent('%+',     down,false);
    VK_DECIMAL   : UserEvent('%,',     down,false);
    VK_INSERT    : if ext then UserEvent('Einfg',  down,true ) else UserEvent('%0',   down,true );
    VK_DELETE    : if ext then UserEvent('Entf',   down,true ) else UserEvent('%,',   down,true );
    VK_END       : if ext then UserEvent('Ende',   down,true ) else UserEvent('%1',   down,true );
    VK_HOME      : if ext then UserEvent('Pos1',   down,true ) else UserEvent('%7',   down,true );
    VK_LEFT      : if ext then UserEvent('L.',     down,true ) else UserEvent('%4',   down,true );
    VK_UP        : if ext then UserEvent('U.',     down,true ) else UserEvent('%8',   down,true );
    VK_RIGHT     : if ext then UserEvent('R.',     down,true ) else UserEvent('%6',   down,true );
    VK_DOWN      : if ext then UserEvent('D.',     down,true ) else UserEvent('%2',   down,true );
    VK_PRIOR     : if ext then UserEvent('Bild',   down,true ) else UserEvent('%9',   down,true );
    VK_NEXT      : if ext then UserEvent('%Bild',  down,true ) else UserEvent('%3',   down,true );
    VK_SELECT,VK_EXECUTE,VK_HELP,VK_SEPARATOR,VK_F13..VK_F24 : Beep;
  end;
end;

Regards... Madshi.

P.S: I copied this function from my sources, so you can ignore the UserEvent calls...
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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

932 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

9 Experts available now in Live!

Get 1:1 Help Now