Bug 309286 - [Workbench] F12 and F10 keys do not receive SWT.KeyDown or KeyPressed event when used in plugin environment.
Summary: [Workbench] F12 and F10 keys do not receive SWT.KeyDown or KeyPressed event w...
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact: Paul Webster CLA
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2010-04-15 06:30 EDT by Bhanu Pratap CLA
Modified: 2018-05-15 15:12 EDT (History)
8 users (show)

See Also:


Attachments
Plugin project zip file containing source code for recreating this bug (13.62 KB, application/zip)
2010-04-15 06:34 EDT, Bhanu Pratap CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bhanu Pratap CLA 2010-04-15 06:30:06 EDT
Build Identifier: I20080617-2000

F12 key does not receive SWT.KeyDown or KeyPressed event when used in eclipse's plugin environment. It works fine if used as a java Application. Similar behaviour is observed for F10 Key.

Reproducible: Always

Steps to Reproduce:
1. Use the F12F10SWTBug.zip to form an eclipse plugin project.
2. Test this plugin by using "Eclipse Application" from Debug/Run Configurations.
   (Eclipse Application should be configured to run org.eclipse.ui.ide.workbench application)
3. Once the eclipse Application is started, go to Window->Show View->Other-> Sample Category -> F12 F10 SWT Bug
4. Once the application is started, its text area displays the Key event recieved. Note that pressing F12 on buttons does not recieve SWT.KeyDown and KeyPressed events. Similarly for F10 Key.
Comment 1 Bhanu Pratap CLA 2010-04-15 06:34:45 EDT
Created attachment 164955 [details]
Plugin project zip file containing source code for recreating this bug
Comment 2 Silenio Quarti CLA 2010-05-19 19:36:35 EDT
SWT is sending the key events. The workbench has a display filter the changes the event type to SWT.None.
Comment 3 Paul Webster CLA 2010-05-20 08:17:02 EDT
F10 opens the left most (File) menu.  F12 activates the open editor.

These are being processed by the keybindings filter (Keys preference page) first.

PW
Comment 4 Sujith Job CLA 2010-05-28 01:37:36 EDT
Is there a way to overwrite the Keybindings?
Comment 5 Paul Webster CLA 2010-05-28 08:04:55 EDT
(In reply to comment #4)
> Is there a way to overwrite the Keybindings?

For F12, change the keybinding in the keys preference page.


For F10, that is done by SWT and cannot be changed.  If you add a menu bar to your SWT only snippet, you'll see you no longer get F10 events at all.

PW
Comment 6 Bhanu Pratap CLA 2010-06-01 00:44:36 EDT
(In reply to comment #3)
> F10 opens the left most (File) menu.  F12 activates the open editor.
> 
> These are being processed by the keybindings filter (Keys preference page)
> first.
> 
> PW

Is this the correct behaviour?? Shouldn't it be like this:

Window which has the focus should get all the events which it has registered for. 
Also, once such application is deployed how are we expecting an end user to know that his/her F12/F10 keys are not working because they are being filtered by environment's key binding filter. 
Here is an example:
We have a product which emulates Host Screen and is in the form of an OSGI container. It is developed on eclipse. Now, if a user wants to send F12 key to the host he would not be able to do so because F12 key doesn't work because it is being consumed by the eclipse's Key binding filter instead of the application window which is in focus.
Comment 7 Paul Webster CLA 2010-06-01 06:08:46 EDT
(In reply to comment #6)
> Also, once such application is deployed how are we expecting an end user to
> know that his/her F12/F10 keys are not working because they are being filtered
> by environment's key binding filter. 

Because your application is responsible for its keybindings.

If you use the default scheme, then you will consume F12.  Publish that.  If you don't want F12 to mean activate editor, then you need to use your own scheme, not the default scheme.  Check out the keybinding extension point description for more information.  This should only be a problem if you are starting up the Workbench (org.eclipse.ui), not if you deploy a bundle in OSGi.

F10 should have an immediately obvious action (jumping to the menu bar and activate the File menu).  But this should only be a problem if you have an SWT Menu bar.  Do you?

The only way I can think of to work around F10 is the way that something like vnc does:  Pick a keybinding that will pop up a menu.  That menu can send that key as well as F10 through your host screen.

The other option is to re-open this bug as an enhancement request against SWT to provide API to allow F10 to be overridden.  That could be looked at in 3.7.

PW
Comment 8 Felipe Heidrich CLA 2010-08-04 11:06:56 EDT
(In reply to comment #5)
> For F10, that is done by SWT and cannot be changed.  If you add a menu bar to
> your SWT only snippet, you'll see you no longer get F10 events at all.

Paul, I was not able to confirm the above:

public static void main(String[] args) {
	Display display= new Display();
	Shell shell= new Shell(display);
	shell.addListener(SWT.KeyDown, new Listener() {
		public void handleEvent(Event e) {
			System.out.println("KeyDown " + e.keyCode);
		}
	});
	shell.addListener(SWT.KeyUp, new Listener() {
		public void handleEvent(Event e) {
			System.out.println("KeyUp " + e.keyCode); 
		}
	});
	Menu menu = new Menu(shell, SWT.BAR);
	shell.setMenuBar(menu);
	MenuItem item = new MenuItem(menu, SWT.CASCADE);
	item.setText("File");
	shell.setSize(300, 300);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

Note that F10 is received by the listener, after that focus moves to the first menu item (which will show in blue). With the menu item blue press another key down, this key down is lost, the menu loses focus.

You can prevent the OS from changing to focus to the menu during f10 by setting doit=false in the event handler.
Comment 9 Paul Webster CLA 2010-08-11 13:42:04 EDT
(In reply to comment #8)
> (In reply to comment #5)
> > For F10, that is done by SWT and cannot be changed.  If you add a menu bar to
> > your SWT only snippet, you'll see you no longer get F10 events at all.
> 
> Paul, I was not able to confirm the above:

With your snippet, I get KeyUp (but no KeyDown on linux).

If I add items under File, then I no longer get any KeyDown or KeyUp

Menu file = new Menu(item);
item.setMenu(file);
new MenuItem(file, SWT.PUSH).setText("One");
new MenuItem(file, SWT.PUSH).setText("Two");
new MenuItem(file, SWT.PUSH).setText("Three");

PW
Comment 10 Bhanu Pratap CLA 2011-03-12 00:20:42 EST
> With your snippet, I get KeyUp (but no KeyDown on linux).
> 
> If I add items under File, then I no longer get any KeyDown or KeyUp
> 
> Menu file = new Menu(item);
> item.setMenu(file);
> new MenuItem(file, SWT.PUSH).setText("One");
> new MenuItem(file, SWT.PUSH).setText("Two");
> new MenuItem(file, SWT.PUSH).setText("Three");
> 
> PW


(In reply to comment #7)
> (In reply to comment #6)

> The other option is to re-open this bug as an enhancement request against SWT
> to provide API to allow F10 to be overridden.  That could be looked at in 3.7.
> 
> PW

Thank you Paul, defining the new key binding for F12 key using org.eclipse.ui.bindings extension point works fine for F12 key.  But the issue with F10 key still remains, and I was also able to confirm the above i.e. No key event received when your application have a SWT Menu bar. 

Going by your suggestion I am re-opening this bug as an enhancement request in SWT component. 


Bhanu
Comment 11 Silenio Quarti CLA 2011-03-14 12:47:55 EDT
(In reply to comment #10)
> > PW
> Thank you Paul, defining the new key binding for F12 key using
> org.eclipse.ui.bindings extension point works fine for F12 key.  But the issue
> with F10 key still remains, and I was also able to confirm the above i.e. No
> key event received when your application have a SWT Menu bar. 
> Going by your suggestion I am re-opening this bug as an enhancement request in
> SWT component. 
> Bhanu

Which platform and eclipse build are you seeing this problem? I believe we fix the problem Paul mentioned above (comment#9) on Linux (see bug#316329).
Comment 12 Bhanu Pratap CLA 2011-03-14 13:10:36 EDT
(In reply to comment #11)
> (In reply to comment #10)
> > > PW
> > Thank you Paul, defining the new key binding for F12 key using
> > org.eclipse.ui.bindings extension point works fine for F12 key.  But the issue
> > with F10 key still remains, and I was also able too confirm the above i.e. No
> > key event received when your application have a SWT Menu bar. 
> > Going by your suggestion I am re-opening this bug as an enhancement request in
> > SWT component. 
> > Bhanu
> 
> Which platform and eclipse build are you seeing this problem? I believe we fix
> the problem Paul mentioned 

I am able to recreate the problem using eclipse 3.6.1 on linux. The sample used to recreate the problem is there in comment#8, with a modification of adding a menu item under the"file"menu. 
The problem is that no key down or key up events are received by the listener when F10 key is pressed, as mentioned by Paul in comment#9. While on windows, only key released event is received. 

Bhanu.
Comment 13 Silenio Quarti CLA 2011-03-14 13:13:38 EDT
bug#316329 was only fixed in 3.7 M2. Please try that build.
Comment 14 Bhanu Pratap CLA 2011-03-15 04:02:49 EDT
(In reply to comment #13)
> bug#316329 was only fixed in 3.7 M2. Please try that build.

Thank you Silenio. I verified with 3.7, the listener was now able to get KeyDown events. Also, noticed that still no KeyUp event for F10 and the focus goes on to the menu bar's first menu item. I guess this behaviour can be changed by overriding the OS's key binding for F10. 

Bhanu.
Comment 15 Eric Williams CLA 2018-05-15 15:12:33 EDT
Closing as per comment 14.