That link was indeed a nice one for my personal purposes.:*
However.
As it goes, the hook is inserted in some Windows API.
I am pretty sure that some viruses can access the keyboard directly via hardware.
All in all, Windows API does just that too, and if you ask a windows API for keyboard events, then this is controlled by this API first. In other words, your program will not be the first to read the keyboard.
Without actually knowing 100% sure, I think the method to use is best done via Assembler code and redirecting Keyboard scan interrupt to your own assembler routines for then to direct the flow of control back to original address of original interrupt.
Back in the old days, before I fell in love with Turbo Pascal, I wrote some simple ASM code on the commodore 64 that redirected interrupts.
A much simpler computer with easier memory handling, but the basics of computers has not changed. Even the most advanced and sophisticated computer today depends on the same basic stuff of interrupts for many actions.
With the layer of Windows on top, it is not easy to find the right information on how to be allowed to change such an interrupt after Windows have started up.
My best suggestion is to write an assembler program, A kind of Keyboard Driver, one that loads into computer memory BEFORE windows starts up.
Windows Keyboard API should then lock its handler onto your driver, and hence leave your driver in first control of the keyboard.
Even if a keylogger is installed afterwards using windows, I think the OS will protect against direct access to interrupts(To a certain extent, and always methods to use to circumvent this for the knowledgeable ones) and leave your driver intact as the first possible place where keyboard input go.
I think a standard keyboard logger would access windows API in such a way that it is "First in que" to get the input, and if well written, it would also contain some code to prevent other software to gain "First in que access".
I hope my thoughts does not kill the curiosity. Maybe some other developers out there have some better insight in how to make this driver, and maybe how to be able to communicate (write interface to driver) so that it can be used via Delphi.
Many Linux developers really enjoy making code in assembler. Maybe something to search for in such a user group.
Just an idea and some thoughts.:twisted:
Best regards.
Morten, Norway