?
Solved

KeyHook.dll

Posted on 1998-12-25
1
Medium Priority
?
216 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 40 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

743 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