gcode-mirror / earth-api-samples

Automatically exported from code.google.com/p/earth-api-samples
0 stars 0 forks source link

Support keyboard events while the GE plugin has the focus #53

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently you can trap keyboard events while the html window has the focus but 
not while the plugin has the focus and mouse events only work properly while 
the plugin has focus. Please add keyboard events to the plugin so we can trap 
both keyboard and mouse events while the plugin has focus.

Requested by: TinyGrasshopper

Supported by: jan.wischnat

Original issue reported on code.google.com by api.roman.public@gmail.com on 12 Aug 2008 at 8:46

GoogleCodeExporter commented 9 years ago
I support this request. Currently we don't have a workaround for keyboard 
events when
the plugin has focus

Razz

Original comment by rjai...@gmail.com on 30 Jan 2009 at 2:30

GoogleCodeExporter commented 9 years ago
keyboard support is essential for serious applications. I wonder if I can use 
the
mouse button up event to shift focus back to the page so keyboard events at 
least get
handled. I suppose that will then kill native keyboard support in GE

Original comment by vandint...@gmail.com on 1 Apr 2009 at 8:16

GoogleCodeExporter commented 9 years ago
I had limited success with the keyboard hack in the source section but the 
following
code is usable in both IE and FF. Obviously you lose keyboard functionality in 
ge and
the mouse scroll wheel will not zoom (Use right mouse drag instead).

google.earth.addEventListener(ge.getWindow(), "mouseup", setPageFocus);

function setPageFocus(){
  window.focus();
}

Original comment by vandint...@gmail.com on 2 Apr 2009 at 9:36

GoogleCodeExporter commented 9 years ago
PERFECT.

Original comment by guerrero...@gmail.com on 6 Aug 2009 at 2:12

GoogleCodeExporter commented 9 years ago
ohhh, No functionate whit Crhome

Original comment by guerrero...@gmail.com on 6 Aug 2009 at 2:40

GoogleCodeExporter commented 9 years ago
chrome does not let you steal focus. that makes chrome a no go zone for now

Original comment by vandint...@gmail.com on 8 Aug 2009 at 7:52

GoogleCodeExporter commented 9 years ago

Original comment by api.roman.public@gmail.com on 9 Aug 2009 at 12:58

GoogleCodeExporter commented 9 years ago
I wanted to add my support for this function, to do some vital functions in my 
application I need to be able to add a keypress/keydown/keyup events that are 
done on 
the earth, having to force focus lost to use the document events is a pain

Original comment by david...@gmail.com on 26 Jan 2010 at 6:00

GoogleCodeExporter commented 9 years ago
Since ge.getWindow().blur(); has been fixed it is possible to use

ge.getWindow().blur(); in the Mouseup event. This will work on all browsers on
Windows but not reliable on Apple where all browsers end up with the focus in 
lala land.

Also you still lose all of the user interface functionality of ge.

With the above code keyboard sort of works as a hack but native keypress events 
are
essential.

Original comment by vandint...@gmail.com on 27 May 2010 at 11:02

GoogleCodeExporter commented 9 years ago

Original comment by bcke...@google.com on 23 Feb 2011 at 12:09

GoogleCodeExporter commented 9 years ago

Original comment by api.roman.public@gmail.com on 28 Jul 2011 at 4:08

GoogleCodeExporter commented 9 years ago
This is related and may not answer everyone's needs, but it answered mine. As 
this happend to be the first place I looked when I started searching I wanted 
to post the solution I found, however obvious it may have been.

//get key modifiers with mouse events
google.earth.addEventListener(ge.getWindow(), 'click', function(event) {
var ctrlKey = kmlEvent.getCtrlKey(); 
if(ctrlKey==1) {
  alert("Ctrl click detected!); 
}

I found this at:  
http://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread/
31afa674ac5ecf5a

Original comment by freeflyh...@gmail.com on 20 Oct 2011 at 4:18

GoogleCodeExporter commented 9 years ago
in 2008 there were reported problems with keyboard events. Now it is 2011. More 
than 3 years later and STILL no solid solution to this issue. Some version of 
Firefox (3.6 and lower) will respond to ge.getWindow().blur(); in the mouseup 
event handler. Newer version of Firefox won't.

After throwing a few more hours at the problem, I came up with the following 
workaround:

I grabbed the HTML button code from the demo gallery and placed such a button 
on top of the ge window. This provided the browser with a visible control to 
set focus to. Then I started to remove code from the button object and was left 
the with following code that leaves an invisible control that can still be 
focused on. 

Place this code in the mouseup event handler:

document.getElementById('takecontrol').focus();

Place this code in the initCallback to create the focus control where map3d is 
the name of the div that holds the ge plugin:

createFocusControl('map3d');

function createFocusControl(containerid) {
    var button = document.createElement('a');
    button.id = 'takecontrol';
    button.href = '#';
    button.style.display = 'block';
    button.innerHTML = 'PIA';
    button.id = 'takecontrol';
    button.style.position = 'absolute';
    button.style.left = '5px';
    button.style.bottom = '5px';
    button.style.width = '25px';
    button.style.height = '18px';
    document.getElementById(containerid).appendChild(button);
};

This control is invisible because the background color is not set. That is just 
perfect for our purpose. If the control is visible it will be placed discretely 
in the lower left corner of the ge window. The code assumes that the map3d div 
is positioned absolute or relative.

This workaround works perfectly with all planetinaction.com applications on 
Firefox, Chrome and MSIE on both Windows XP and Windows7. I hope someone can 
give feedback on how well this works for Apple (If required at all)

Original comment by vandint...@gmail.com on 30 Oct 2011 at 11:24

GoogleCodeExporter commented 9 years ago
Thanks for the workaround. Unfortunately it also prevents the plugin to receive 
the navigation keystrokes (arrow buttons etc.), but more than nothing:)

I slightly modified the code: setting the innerHTML to ' ' will ensure that 
nothing appears on the screen while it is still getting the focus.

Original comment by samanocs...@gmail.com on 8 Dec 2011 at 9:05

GoogleCodeExporter commented 9 years ago
Wow... 5 years?

Definitely an needed feature. 

Original comment by carson.p...@gmail.com on 6 Mar 2013 at 10:02