Board index » delphi » Capture Keystrokes

Capture Keystrokes

Whats the most straight forward way to capture and record keystrokes even
when the program does not have focus? Running in system tray as icon for
example.
 

Re:Capture Keystrokes


Hi drey,

on Fri, 18 May 2001 08:06:49 -0400 you wrote:

Quote
> Whats the most straight forward way to capture and record keystrokes even
> when the program does not have focus? Running in system tray as icon for
> example.

You need a global keyboard hook for that. Check http://groups.google.com
for these keywords.

Cheers,
   Udo
--
Homepage: http://www.nesshoever.de            No mails please. Reply here.

                                     Global Polio Awareness Campaign 2001+
                                         More info -> http://www.2-mad.com

Re:Capture Keystrokes


Thanks Udo for the link. I have searched through all the documentation and
at least understand what I have to have to accomplish the hook, however,
through all the searching I only found examples in Delphi and VB. I have
also found out this appears to be an advanced function, so maybe I am biting
off more than I can chew, but with a decent bcb c++ example I believe I
could fiqure it out. It doesn't look like to much coding. I would need an
example of how to call the hook dll in my exe and since I have never had to
write my own dll, some kind of example of how the hook should be declared in
BCB C++. I have v5 pro. Any help would be appreciated.

drey

Re:Capture Keystrokes


Hi drey,

on Sat, 19 May 2001 12:58:04 -0400 you wrote:

Quote
> Thanks Udo for the link. I have searched through all the documentation and
> at least understand what I have to have to accomplish the hook, however,
> through all the searching I only found examples in Delphi and VB. I have
> also found out this appears to be an advanced function, so maybe I am biting
> off more than I can chew, but with a decent bcb c++ example I believe I
> could fiqure it out. It doesn't look like to much coding. I would need an
> example of how to call the hook dll in my exe and since I have never had to
> write my own dll, some kind of example of how the hook should be declared in
> BCB C++. I have v5 pro. Any help would be appreciated.

And here comes the problem. I'm a Delphi pro but a C++ newbie and
although I can give you some general tips there's no way for me at the
moment to give you a working example of c++ code. Sorry.

Cheers,
   Udo
--
Homepage: http://www.nesshoever.de            No mails please. Reply here.

                                     Global Polio Awareness Campaign 2001+
                                         More info -> http://www.2-mad.com

Re:Capture Keystrokes


lol. I know what ya mean. I even have Delphi v4 but have only fired it up
and looked at it. I would not even know where to start, although I believe
it is very close to c++. Anyway, thanks for your input. In the meen while I
did find some code but I can't get a portion of it to compile. I have never
tried to call a function in an exe out of a dll, but logically speaking, and
the fact it is suppose to be code that works, it looks like it should. For
anybody else out there, heres what I have.

EXE portion. I put this in an OnClick event for now because I really have no
idea what it's going to do at run time.

void __fastcall TConsoleForm::Button1Click(TObject *Sender)
{

  FARPROC  KeylogHookProc;
  HINSTANCE KeylogDLL;
  HHOOK  KeylogHook;

  KeylogDLL=LoadLibrary("Keylog.dll"); /this appears to open the dll to the
exe?
  KeylogHookProc=GetProcAddress(KeylogDLL,"KeyboardHookProc"); /this appears
to access the process I want?
  KeylogHook=SetWindowsHookEx(WH_KEYBOARD,KeyboardHookProc,KeylogDLL,NULL);
/heres where I get the error "Undefined         KeyboardHookProc"

Quote
}

When this compiles it says undefined KeyboardHookProc. Now I know it is not
defined in the EXE, but from the code above, I thought it would go out to
the dll and get the Proc there.

Heres the Dll.

 LRESULT CALLBACK KeyboardHookProc( int code,WPARAM key, LPARAM lParam)
{
    //Your code to log the keys goes here

    return CallNextHookEx(NULL, code, key, lParam);

Quote
}

So as you can see, KeyboardHookProc is defined here but is the code in the
EXE capable of checking this during compile? Do I have to add or include
something to the EXE to get it to find it? I'll keep praying for help. Udo,
maybe from this you can do some C++/Delphi converting? lol.

drey.

Re:Capture Keystrokes


Hi drey,
on Sun, 20 May 2001 19:38:13 -0400 you wrote:

Quote
> lol. I know what ya mean. I even have Delphi v4 but have only fired it up
> and looked at it. I would not even know where to start, although I believe
> it is very close to c++. Anyway, thanks for your input.

Actually I started reading some C++ groups, was browsing all groups,
found your subject and replied without noticing I was posting to a C++
group ;) I normally start reading tons of messages of a group before I
post there. Anyway. Glad I could help, at least guide you into the right
direction.

BTW: C++ might be a little more powerful (regarding the ability to write
drivers) but IMHO there's nothing comparable to the RAD IDE of Delphi
(so you should consider using Borland's C++ Builder to have a C++ RAD
IDE. But that's getting OT and it's only my $0.02)

Cheers,
   Udo
--
Homepage: http://www.nesshoever.de            No mails please. Reply here.

                                     Global Polio Awareness Campaign 2001+
                                         More info -> http://www.2-mad.com

Other Threads