PDA

View Full Version : Keboardlayout



hmarani
17th February 2011, 16:34
Hi,
In lineedit, I like to force it type in Farsi(Persian, which it is activated in windows xp). I can do that in vb by using
GetKeyboardLayout(0) to 67699721
then ActivateKeyboardLayout(0) .How can I do it in Qt, please help.
Thanks

stampede
17th February 2011, 17:15
Qt is C++, you can use any winapi function, just include "windows.h" and use ActivateKeyboardLayout (http://msdn.microsoft.com/en-us/library/ms646289(v=vs.85).aspx)

hmarani
17th February 2011, 17:25
Thanks a lot; Any examples or link,hint over Internet in this regard?
Thanks again

hmarani
17th February 2011, 19:30
There is HKL type conversion issue


t=GetKeyboardLayout(0)
if t=67699721
t=Activat...

What should be before t for declaring (int, QString or QVariant are not acceptable), sorry for the .... question
please help
thanks

ChrisW67
17th February 2011, 21:26
Declare it to be of type HKL, which should be included as a result of including windows.h.

hmarani
17th February 2011, 22:16
I did but then I cannot write :


if (t=67699721)

the compiler give me error of wrong conversion I tried :


int t= GetKeyboardLayout(0)->i;
if (t=67699721)
t=ActivateKeyboardLayout(0,0)->i;

the compiler does not complain but it does not type correct Persian; it types cobination of Persian with some
other languages; I appriciate your help, a lot

stampede
17th February 2011, 22:35
if (t=67699721)
If you are new to C / C++, above line is assignment, not equality test. It sets 't' to have value 67699721, and returns that value. If you want compare values, use 't==other_value'.

According to documentation, there is a method named LoadKeyboardLayout (http://msdn.microsoft.com/en-us/library/ms646305(v=vs.85).aspx). It expects a "language identifier string", take a look at this list (http://msdn.microsoft.com/en-us/library/dd318693(v=vs.85).aspx), you can find there id of Persian locale to be 0x0429, so according to this:

For example, U.S. English has a language identifier of 0x0409, so the primary U.S. English layout is named "00000409".
you should try somethig like:

LoadKeyboardLayout(L"00000429",KLF_ACTIVATE); //!< im not sure about the L ...
Finally, check the output of this method and use GetLastError (http://msdn.microsoft.com/en-us/library/ms679360(v=vs.85).aspx) to know details if something will go wrong.

Please note that I haven't tried the above code, I'm just guessing how this should look like according to microsoft docs.

-------
edit: I'm not sure about the KLF_ACTIVATE flag either, maybe you'll need to try with other values (described in first link in this post)

hmarani
17th February 2011, 23:02
Thanks, I will.

hmarani
18th February 2011, 14:31
Solved, Thanks a lot.
should use == instead of= and the code is 404226304