Solved

KeyHook.dll

Posted on 1998-12-25
1
212 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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