[C++] Get and save whole Keyboard (Text) Input without Keyboard Hook

03/24/2012 01:43 SILENTChris#1
Credits: me (silentchris)

Alright, this shit will work with ALL Keyboards :)
And you wont need to use a Keyboard Hook, which is, btw., gettin detected by some Anticheats ;)

// Gets the current pressed key by looping thru all fkin vKey Codes
Code:
DWORD FetchKeyCode( )
{
    DWORD i        = 0x00;
    DWORD ret    = 0x00;

    do
    {
        if( GetAsyncKeyState(i)&0x1 )
            ret = i;
        i++;
    }
    while( !ret && i < 0xFF );

    return ret;
}
// Gets the correct char of Virtual Key Codes AND also takes care about special character and even about shift (Upperletters)
Code:
char VKtoCHAR(int vk)
{
    static UCHAR keyboardState[256];
    USHORT asciiVal;

    // get layout
    static HKL layout = GetKeyboardLayout(0);

    // get keyboard state (shift etc)
    if( GetKeyboardState(keyboardState) == false )
        return 0;

    // yup get ASCII codezZz :)
    if( ToAsciiEx( vk, MapVirtualKey(vk,0), keyboardState, &asciiVal, 0, layout ) == 0 )
        return 0;

    return static_cast<char>(asciiVal);
}

// Use this to get final stuff
Code:
int vKey = (int)FetchKeyCode();

char c = VKtoCHAR(vKey);

c is ur single char now.
you can attach it to a string or w.e
03/24/2012 21:58 link#2
this be leet shit nigga