I have used sendinput() function and windows keyboard hooks to develop a custom keyboard for indian languages.
Project is in google code here: http://code.google.com/p/ekalappai
The keyboad hook and sendinput functions are placed in a win32 dll. And they are called from a Qt exe.
Our application works fine for most keys and applications. I find the following issue:
I could not send Backspace key to few applications like Wordpad/Openoffice/MsOffice. I find same issue with Arrowkeys and delete keys.
Here is my code:
extern "C" __declspec(dllexport) void GenerateKey(int vk , bool bExtended)
{
//update previous characters
previous_2_character = previous_1_character;
previous_1_character = vk;
KEYBDINPUT kb={0};
INPUT Input={0};
//keydown
kb.wVk = 0;
kb.wScan = vk;/*enter unicode here*/;
kb.dwFlags = KEYEVENTF_UNICODE; // KEYEVENTF_UNICODE=4
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
//keyup
kb.wVk = 0;
kb.wScan = vk;/*enter unicode here*/;
kb.dwFlags = KEYEVENTF_UNICODE|KEYEVENTF_KEYUP; //KEYEVENTF_UNICODE=4
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
}
Full dll code is here: http://code.google.com/p/ekalappai/source/browse/trunk/ekhook/ekhook/dllmain.cpp
Calling code:
generatekey = (GenerateKey) myLib->resolve( "GenerateKey" );
generatekey(44,FALSE); //comma - THis works in wordpad/MsOffice/Openoffice
generatekey(2949,FALSE); //tamil character "a" works in Wordpad/Msoffice/Openoffice
generatekey(8,FALSE); //backspace - This is NOT working in Wordpad/Msoffice/Openoffice
Full calling code from Qt Exe is here:
http://code.google.com/p/ekalappai/source/browse/trunk/ekalappai/window.cpp
I tried searching in google but could not fine a solution yet. If anyone has clue on resolving this pls help. Thanks.
You are mixing up the virtual key and the scan code. The wVk member is the important one, the scan code will only be used it the virtual key is ambiguous. Fix: