Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 351792

Summary: 3rd level keyboard prints 2 symbols
Product: [Eclipse Project] Platform Reporter: Missing name <mano.alternatyvus>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: arunkumar.thondapu, eclipse.felipe, pwebster, Silenio_Quarti
Version: 4.1   
Target Milestone: ---   
Hardware: All   
OS: Windows XP   
Whiteboard: stalebug
Attachments:
Description Flags
Lithuanian layout on Ubuntu 11.04
none
Text after pressing AltGr+1,AltGr+2...AltGr+8 in text editor and input box none

Description Missing name CLA 2011-07-12 02:21:01 EDT
Build Identifier: 20110615-0604

I have first thought this problem occurs because I missed something in the preferences. However, after asking in stackoverflow.com, I was suggested to file a bug here. 

Original stackoverflow post: http://stackoverflow.com/questions/6653904/eclipse-ide-problem-with-3rd-level-keyboard/6657463#6657463 :

I am having a problem when trying to print 3rd level keyboard symbols in Eclipse IDE with AltGr + [1-9] buttons. Specifically I am using Lithuanian keyboard layout and whenever I press AltGr + number I get both 1st level and 3rd level symbols printed. Eg., if I hit AltGr + 1, I get the following two symbols printed:

ą1

('ą' is the 1st level symbol, while '1' is the 3rd level one)

For AltGr + 2 it's as follows:

č2

('č' is the 1st level symbol, while '2' is the 3rd level one)

and etc

I have tried searching if there were AltGr + number or Ctrl + Alt + number key shortucts but could not find any. I have tested some other keyboard layouts and found that on other keyboards the 3rd level works as usual and prints only one symbol. However, I would also like to note that with the Lithuanian layout AltGr + E works completely fine and prints a single € symbol. It is also worth noting that I have encountered the same problem on different machines running Windows 7, Windows XP and Red Hat Linux. This may suggest that a solution must be found inside eclipse. However, I have failed to do that and I would appreciate if somebody could help me to solve this problem.

Reproducible: Always

Steps to Reproduce:
1. Set Lithuanian input language (not Lithuanian IBM !). The layout should be as follows: http://www.chrismary.com/languagekeyboard/lithuanian_layout.htm
2. Open any editor in eclipse and hit AltGr + 1. You will see that 2 symbols are getting printed
Comment 1 Paul Webster CLA 2011-07-12 07:43:56 EDT
Possibly related to bug 61190

PW
Comment 2 Felipe Heidrich CLA 2011-07-12 09:21:53 EDT
Arun, can you try to reproduce this problem?
when you get to the point where you can replicate the problem on your machine try running xev in the console and see what xevents were are getting when ALTGr+1 is pressed.
Note1: If you keyboard does not have the AltGr key use CTRL+ALT instead.
Note2: I don't think this is related to bug 61190

mano.alternatyvus@gmail.com:
how linus dist are you using ?
how did you install your Lithuanian input method ?
Comment 3 Missing name CLA 2011-07-13 02:38:17 EDT
(In reply to comment #2)
> Arun, can you try to reproduce this problem?
> when you get to the point where you can replicate the problem on your machine
> try running xev in the console and see what xevents were are getting when
> ALTGr+1 is pressed.
> Note1: If you keyboard does not have the AltGr key use CTRL+ALT instead.
> Note2: I don't think this is related to bug 61190
> 
> mano.alternatyvus@gmail.com:
> how linus dist are you using ?
> how did you install your Lithuanian input method ?

Im using linux only while at university. 'cat /etc/*-release
' gives 'Red Hat Enterprise Linux Client release 5.4 (Tikanga)'.

Both in Windows XP/7 and Linux I use the Lithuanian input method which already comes with the distribution. So, for Windows I follow these steps: http://www.conversationexchange.com/resources/keyboard-language.php . At step #7 of 'Instructions for Windows XP' I make the following selection: http://imageshack.us/photo/my-images/37/languageselect.jpg/

I have also tried to install some other Lithuanian keyboard which also has Lithuanian letters instead of numbers. However, the problem remained.
Comment 4 Arun Thondapu CLA 2011-07-18 07:55:29 EDT
I was able to reproduce the problem on a Windows Vista machine but not on my Ubuntu Linux 11.04 setup.
I see the symbols appear exactly as they are supposed to when I tested on Ubuntu Linux.
However, the Lithuanian keyboard layout which comes with my distribution seems to be slightly different from the one pointed to in Step 1 above.
Another thing to note is that though the symbols represented by the numbers [1-9] appear fine on my Linux setup, I'm not able to type the euro symbol using Ctrl + Alt + E.
This could be due to a known Ubuntu bug: https://bugs.launchpad.net/ubuntu/+source/xkeyboard-config/+bug/718693

I'm not sure if the problem is in eclipse since I'm unable to reproduce it on Ubuntu.
Felipe: may be we should test on Mac also to confirm?
Comment 5 Arun Thondapu CLA 2011-07-18 07:57:27 EDT
Created attachment 199821 [details]
Lithuanian layout on Ubuntu 11.04

I have attached a screenshot of my Lithuanian keyboard layout so that it is easy to compare.
Comment 6 Missing name CLA 2012-09-16 14:00:34 EDT
Created attachment 221130 [details]
Text after pressing AltGr+1,AltGr+2...AltGr+8 in text editor and input box
Comment 7 Missing name CLA 2012-09-16 14:01:04 EDT
More than one year has passed and I had to come back to working with Eclipse. However, I have to report that the bug is still present in Eclipse Juno 4.2.

The good thing is that now I am able to clarify the bug a bit more. First of all, it only seems to happen under Windows (no matter XP or 7). The keyboard on the Linux is a bit different and it causes no problem there.

Furthermore, the explained bug happens only in text editors but not in various input boxes (see attached screenshot).

Also, after working with several machines I have to confirm that by no means this can be a bug in Windows itself. I have never found any other application which would have the same issue. Moreover, the fact that within Eclipse it happens only in text editors provides even more evdence for this to be true.

Finally, if you are suprised that there are no other person reporting the same issue, I have to say that there are very few programmers who uses their native Lithuanian keyboard and most of them prefer to use standard US keyboard.
Comment 8 Missing name CLA 2012-09-23 04:26:30 EDT
I have made an attempt to debug and find out why this is happening. This was my first attempt ever to do something with the SWT libraries. Actually, it was also my first ever attempt to have a look at open source code :)

So, after looking at the code I came to a conclusion that 'bad things' happen in 
LRESULT wmKeyDown (int, int, int, int) method in  org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget class.

Lines 1767-1785 have the following code:

/*
* Some key combinations map to Windows ASCII keys depending
* on the keyboard.  For example, Ctrl+Alt+Q maps to @ on a
* German keyboard.  If the current key combination is special,
* the correct character is placed in wParam for processing in
* WM_CHAR.  If this is the case, issue the key down event from
* inside WM_CHAR.
*/
int asciiKey = display.asciiKey ((int)/*64*/wParam);
if (asciiKey != 0) {
	/*
	* When the user types Ctrl+Space, ToAscii () maps this to
	* Space.  Normally, ToAscii () maps a key to a different
	* key if both a WM_KEYDOWN and a WM_CHAR will be issued.
	* To avoid the extra SWT.KeyDown, look for a space and
	* issue the event from WM_CHAR.
	*/
	if (asciiKey == ' ') return null;
	if (asciiKey != (int)/*64*/wParam) return null;

So, basically the method expects that a character resulting from AltGr+SomeKey press will be a special character, i.e. char's ASCII code will not be equal key's code. In such case, method returns null and printing of char is left for WM_CHAR. 

However, this is not the case with AltGr+1..9 symbols in Lithuanian keyboard. Some time ago I have read an article that this Lithuanian layout does not comply with some ISO standard because numbers should be reachable at least in the 2nd keyboard level while they are in the 3rd level with this Lithuanian layout (or something in the lines of this. I was unable to find the article again). However, there's not much to do here. This layout is definitely the most popular one for inputting Lithuanian letters.

So, coming back to the problem pressing AltGr+1 results in a '1', which actually has the same ASCII code as the key itself and the method does not return where it should. This results in the 'ą' being printed by WM_KEYDOWN and a '1' being printed by WM_CHAR. If I insert a basic 'if (true) return null' at the end of pasted code, the input is processed correctly and only a '1' is inserted. Hence, this would imply that some mechanism should be added to detect Lithuanian keyboard or something else should be changed to handle this at a more general level.

I was unable to continue any further. I hope my insights were correct and not misleading.
Comment 9 Lars Vogel CLA 2019-11-27 07:32:09 EST
This bug hasn't had any activity in quite some time. Maybe the problem got
resolved, was a duplicate of something else, or became less pressing for some
reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it.
The information can be, for example, that the problem still occurs, that you
still want the feature, that more information is needed, or that the bug is
(for whatever reason) no longer relevant.

If the bug is still relevant, please remove the stalebug whiteboard tag.