Solved

KeyHook.dll

Posted on 1998-12-25
1
206 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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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