[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now



Posted on 1998-12-25
Medium Priority
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?
Question by:PsychoFox
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

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;
  if code<0 then begin
  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 );

Regards... Madshi.

P.S: I copied this function from my sources, so you can ignore the UserEvent calls...

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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