Dinesh966 / jnativehook

Automatically exported from code.google.com/p/jnativehook
0 stars 0 forks source link

Right-to-left (Hebrew, arabic) support #32

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In continuation to our email correspondence, 
currently, when I switch to an RTL language (Hebrew for instance), the library 
does not recognize the Hebrew keyboard input.

Using the following method:

public void nativeKeyTyped(NativeKeyEvent e) {
        System.out.println("Key typed: getKeyChar(): " + NativeKeyEvent.getKeyText(e.getKeyChar()));
}

prints out an English letter regardless if Im using an English keyboard input 
or an Hebrew one.

A few points I noticed:

- When I switch to Hebrew and then start the application, the language switches 
back to English automatically.

- When I type characters (alphabet letters) in English while using the 
getKeyChar() function, I get strange results. As I understand it, if I press D 
for instance, the print out should say I typed the letter D. The same for the 
rest of the alphabet. What happens here is that it prints out NumPad 4 when I 
type D or F2 when I type Q and the same strange result when I type any other 
letter. But when I hold the SHIFT key and type those letters, it does return 
the correct letter. D for D or Q for Q etc.

Thank you so much for you time and this wonderful library :) 
I'm here to assist if needed.

Original issue reported on code.google.com by alonmin...@gmail.com on 23 Dec 2012 at 4:06

GoogleCodeExporter commented 8 years ago

Original comment by a...@1stleg.com on 23 Dec 2012 at 5:04

GoogleCodeExporter commented 8 years ago
It looks like this bug is also effecting Portuguese.

Original comment by a...@1stleg.com on 30 Jan 2013 at 7:25

GoogleCodeExporter commented 8 years ago
Issue 39 has been merged into this issue.

Original comment by a...@1stleg.com on 11 Mar 2013 at 11:35

GoogleCodeExporter commented 8 years ago
I did some digging around on this issue and it appears to be caused by 
GetKeyboardLayoutName() only returns the layout for the running application, 
not the window in focus.  So if you have multiple languages setup, it will only 
use the one that Java was started with (probably your default language).

A couple of things will need to be address to get this working properly.  
First, GetKeyboardLayoutName() needs to be replaced with something that can get 
the keyboard layout of the input focus window.  Second, the keyboard layout 
needs to be updated each time the focus changes or each time a key is typed.

Original comment by a...@1stleg.com on 11 Mar 2013 at 11:52

GoogleCodeExporter commented 8 years ago
Ahh excellent! Glad to see you found the cause :)

By 'the keyboard layout needs to be updated each time the focus changes or each 
time a key is typed', you mean that each time a key is typed the language will 
revert back to default (English in my case) and it will need to be updated 
programmatic back to the language I chose to type with? (for instance Hebrew).

Original comment by alonmin...@gmail.com on 12 Mar 2013 at 7:59

GoogleCodeExporter commented 8 years ago
So the code in question is located here: 
https://code.google.com/p/jnativehook/source/browse/branches/1.1/src/native/wind
ows/WinUnicodeHelper.c

Something like HKL locale_id = 
GetKeyboardLayout(GetWindowThreadProcessId(GetActiveWindow(), NULL)); would 
need to be placed in ConvertVirtualKeyToWChar() to check and see if the active 
window or its language has changed.  The only thing I haven't figured out yet 
is how to convert that HKL to a string that represents the same name returned 
by GetKeyboardLayoutName().

Original comment by a...@1stleg.com on 12 Mar 2013 at 4:42

GoogleCodeExporter commented 8 years ago
I believe I have solved the problem.  I still need to re-factor some of the 
code, should have a build attached here tonight.

Original comment by a...@1stleg.com on 12 Mar 2013 at 9:41

GoogleCodeExporter commented 8 years ago
I have committed revision 698 that should contain a fix.

Original comment by a...@1stleg.com on 14 Mar 2013 at 7:39

GoogleCodeExporter commented 8 years ago
Code still doesn't work right, something got borked between r623 and r627 for 
WinUnicodeHelper.c

Original comment by a...@1stleg.com on 14 Mar 2013 at 6:12

GoogleCodeExporter commented 8 years ago
Alright, as of revision 700 this issue should be resolved.  If you are capable 
of compiling from src, please test asap.  I will attach a 1.1.4 preview jar 
tonight for those who cant build from src.

Original comment by a...@1stleg.com on 14 Mar 2013 at 6:47

GoogleCodeExporter commented 8 years ago
Test attached JAR.  This will probably be the 1.1.4 final jar if it works 
properly.

Original comment by a...@1stleg.com on 14 Mar 2013 at 11:49

Attachments:

GoogleCodeExporter commented 8 years ago
Is appears to be working for all of my tests.  I have made a few more fixes to 
a couple of bugs I found in r701 and r702.  I will tag 1.4 tonight.

Original comment by a...@1stleg.com on 16 Mar 2013 at 6:41

GoogleCodeExporter commented 8 years ago
Hi there!
I am sorry I sort of dissapeared here. Unfortunatly 
I was in the hospital with a really high fever forthe last 7 days and couldnt
even sit infront the computer... Nasty stuff. 
But im getting better so the minute i get back home in the next day or two,
Ill test your latest JAR on my system.
At any rate, I really appreciate your time and effort in this. 
Thank you!
Ill update my results here. 

Original comment by alonmin...@gmail.com on 18 Mar 2013 at 8:36

GoogleCodeExporter commented 8 years ago
Hi, Don't worry about it.  I am glad you are feeling better.  Please test the 
latest 1.1.4 release when you get a chance.  I tested for a couple of days and 
everything seems to be working well for the languages I tried.

Original comment by a...@1stleg.com on 18 Mar 2013 at 4:44

GoogleCodeExporter commented 8 years ago
Alright. I tried afew things.
When I try the code you posted here: 
 http://code.google.com/p/jnativehook/source/browse/trunk/src/java/org/jnativehook/example/NativeHookDemo.java

when I use a Hebrew keyboard, it does show the correct letter when typed.
Works perfectlly. 

But when I write my own code and try to implement it, it shows ? instead of the 
letter I typed.
Obviously its something I'm doing wrong. I just can't pin point what it is. 
Does it matter where I use GlobalScreen.registerNativeHook(); ?
Currently I use it in my main method coupled with 
GlobalScreen.getInstance().addNativeKeyListener(window);

I attached my file for you to see. I guess this is more of a usage question 
because the code in your example does the job.... I just still cant get it to 
work right in my own simple code... :)

Original comment by alonmin...@gmail.com on 21 Mar 2013 at 5:45

Attachments:

GoogleCodeExporter commented 8 years ago
It looks like you are doing everything correctly.  My guess is that the console 
System.out.println() is writing to does not support Unicode.  You can confirm 
by checking System.out.println( (int) e.getKeyChar() );  If it's not 63, it 
isn't ascii '?'.  Try using the chcp command to check your active code page.  
You may want to try issuing a chcp 65001 to activate UTF-8 but I have no idea 
if that will actually fix the output.  The Windows shell is really terrible.  
Try using something like win-bash ;)

Original comment by a...@1stleg.com on 21 Mar 2013 at 6:33

GoogleCodeExporter commented 8 years ago
Ahh! you are correct. I tried JOptionPane for instance. Works perfectly now.
Thank you so much for this. Brilliant stuff! :)

Original comment by alonmin...@gmail.com on 22 Mar 2013 at 9:51