Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Key event handling in RAP
Key event handling in RAP [message #508537] Tue, 19 January 2010 10:46 Go to next message
Niels Lippke is currently offline Niels LippkeFriend
Messages: 71
Registered: December 2009
Member
Hello RAP experts,

Using accelerator keys is crual for the acceptance of a RIA in our company
and for our customers. Most of the power users use their keyboard instead of
mouse. At least the common CTRL keys must work. So I need to find a way to
prevent the browsers default key event behaviour (which is not actually the
problem) and add inject those events into RAP (for which I have currently no
idea about).

I read a little about Qooxdoo and their mapping between native and their own
event types. Does RAP use the same mechanism? Is there any documentation
about key event handling in RAP? What's the best place to hook into the
sources? Or where to start...

Thanks,

Niels
Re: Key event handling in RAP [message #509029 is a reply to message #508537] Thu, 21 January 2010 03:42 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2427
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi Niels,

the key event stateMask hold an information about CTRL/SHIFT/ALT key
pressed in the time when the event is fired.

HTH,
Ivan

On 1/19/2010 12:46 PM, Niels Lippke wrote:
> Hello RAP experts,
>
> Using accelerator keys is crual for the acceptance of a RIA in our
> company and for our customers. Most of the power users use their
> keyboard instead of mouse. At least the common CTRL keys must work. So
> I need to find a way to prevent the browsers default key event
> behaviour (which is not actually the problem) and add inject those
> events into RAP (for which I have currently no idea about).
>
> I read a little about Qooxdoo and their mapping between native and
> their own event types. Does RAP use the same mechanism? Is there any
> documentation about key event handling in RAP? What's the best place
> to hook into the sources? Or where to start...
>
> Thanks,
>
> Niels
Re: Key event handling in RAP [message #509056 is a reply to message #508537] Thu, 21 January 2010 09:48 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
Niels,

for an example on how to listen "globally" for client-side key events,
see the Application.js file in the org.eclipse.rap.rwt.q07 bundle.
In communicate interest in and occurence of key events between client
and server you may (mis-)use a custom widget or phase listeners.

HTH,
Rüdiger
--
Rüdiger Herrmann
http://eclipsesource.com


On 19.01.2010 11:46, Niels Lippke wrote:
> Hello RAP experts,
>
> Using accelerator keys is crual for the acceptance of a RIA in our
> company and for our customers. Most of the power users use their
> keyboard instead of mouse. At least the common CTRL keys must work. So I
> need to find a way to prevent the browsers default key event behaviour
> (which is not actually the problem) and add inject those events into RAP
> (for which I have currently no idea about).
>
> I read a little about Qooxdoo and their mapping between native and their
> own event types. Does RAP use the same mechanism? Is there any
> documentation about key event handling in RAP? What's the best place to
> hook into the sources? Or where to start...
>
> Thanks,
>
> Niels
Re: Key event handling in RAP [message #509096 is a reply to message #508537] Thu, 21 January 2010 06:46 Go to previous messageGo to next message
Niels Lippke is currently offline Niels LippkeFriend
Messages: 71
Registered: December 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_001E_01CA9A97.8CE50940
Content-Type: text/plain;
format=flowed;
charset="iso-8859-1";
reply-type=response
Content-Transfer-Encoding: 7bit

Hmm, before I get lost in the wood. Here are my current thoughts about the
key bindings.

Attached is a sample html page containing some js-functions I found in the
web. These functions allow the user to override the default browser
behaviour (e.g. CTRL-S which normally open the Save As Dialog in FF and
other browsers) with a custom function.
Here it overides CTRL-S to open an alert window.

So why not do similar in a RAP application and use those key-combinations
for global key bindings (e.g. org.eclipse.ui.bindings)?

Are there problems I don't quite grasp?

Regards,
Niels

------=_NextPart_000_001E_01CA9A97.8CE50940
Content-Type: text/html;
name="test.html"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="test.html"

<html>

<body> =20
<script type=3D"text/javascript">
/**
* http://www.openjs.com/scripts/events/keyboard_shortcuts/
* Version : 2.01.B
* By Binny V A
* License : BSD
*/
shortcut =3D {
'all_shortcuts':{},//All the shortcuts are stored in this array
'add': function(shortcut_combination,callback,opt) {
=09
var eventtype;
//Whether Browser is Gecko based
//alert(navigator.appName);
//alert(navigator.userAgent);
var ua =3D navigator.userAgent; =09
if (ua.indexOf("Safari") > 0) {
eventtype =3D 'keydown';
} else if (ua.indexOf("Opera") > 0) {
eventtype=3D'keypress'; =09
} else if (ua.indexOf("MSIE") > 0) {
eventtype=3D'keydown';
} else if (ua.indexOf("Firefox") > 0) {
eventtype=3D'keypress';
} else if (ua.indexOf("Chrome") > 0) {
eventtype=3D'keypress';
}
/*if (navigator.product =3D=3D 'Gecko') {
eventtype=3D'keypress'; =09
}
else {
eventtype =3D 'keydown';
}*/
//Provide a set of default options
var default_options =3D {
'type': eventtype,
'propagate': false,
'disable_in_input': false,
'target': document,
'keycode': false
}
=09
//Provide a set of default options
//var default_options =3D {
// 'type':'keydown',
// 'propagate':false,
// 'disable_in_input':false,
// 'target':document,
// 'keycode':false
//}
if(!opt) opt =3D default_options;
else {
for(var dfo in default_options) {
if(typeof opt[dfo] =3D=3D 'undefined') opt[dfo] =3D =
default_options[dfo];
}
}

var ele =3D opt.target;
if(typeof opt.target =3D=3D 'string') ele =3D =
document.getElementById(opt.target);
var ths =3D this;
shortcut_combination =3D shortcut_combination.toLowerCase();

//The function to be called at keypress
var func =3D function(e) {
e =3D e || window.event;
=09
if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, =
Textarea fields
var element;
if(e.target) element=3De.target;
else if(e.srcElement) element=3De.srcElement;
if(element.nodeType=3D=3D3) element=3Delement.parentNode;

if(element.tagName =3D=3D 'INPUT' || element.tagName =3D=3D =
'TEXTAREA') return;
}
=09
//Find Which key is pressed
if (e.keyCode) code =3D e.keyCode;
else if (e.which) code =3D e.which;
var character =3D String.fromCharCode(code).toLowerCase();
=09
if(code =3D=3D 188) character=3D","; //If the user presses , when the =
type is onkeydown
if(code =3D=3D 190) character=3D"."; //If the user presses , when the =
type is onkeydown

var keys =3D shortcut_combination.split("+");
//Key Pressed - counts the number of valid keypresses - if it is same =
as the number of keys, the shortcut function is invoked
var kp =3D 0;
=09
//Work around for stupid Shift key bug created by using lowercase - =
as a result the shift+num combination was broken
var shift_nums =3D {
"`":"~",
"1":"!",
"2":"@",
"3":"#",
"4":"$",
"5":"%",
"6":"^",
"7":"&",
"8":"*",
"9":"(",
"0":")",
"-":"_",
"=3D":"+",
";":":",
"'":"\"",
",":"<",
".":">",
"/":"?",
"\\":"|"
}
//Special Keys - and their codes
var special_keys =3D {
'esc':27,
'escape':27,
'tab':9,
'space':32,
'return':13,
'enter':13,
'backspace':8,
=09
'scrolllock':145,
'scroll_lock':145,
'scroll':145,
'capslock':20,
'caps_lock':20,
'caps':20,
'numlock':144,
'num_lock':144,
'num':144,
=09
'pause':19,
'break':19,
=09
'insert':45,
'home':36,
'delete':46,
'end':35,
=09
'pageup':33,
'page_up':33,
'pu':33,
=09
'pagedown':34,
'page_down':34,
'pd':34,
=09
'left':37,
'up':38,
'right':39,
'down':40,
=09
'f1':112,
'f2':113,
'f3':114,
'f4':115,
'f5':116,
'f6':117,
'f7':118,
'f8':119,
'f9':120,
'f10':121,
'f11':122,
'f12':123
}
=09
var modifiers =3D {=20
shift: { wanted:false, pressed:false},
ctrl : { wanted:false, pressed:false},
alt : { wanted:false, pressed:false},
meta : { wanted:false, pressed:false} //Meta is Mac specific
};
=20
if(e.ctrlKey) modifiers.ctrl.pressed =3D true;
if(e.shiftKey) modifiers.shift.pressed =3D true;
if(e.altKey) modifiers.alt.pressed =3D true;
if(e.metaKey) modifiers.meta.pressed =3D true;
=20
for(var i=3D0; k=3Dkeys[i],i<keys.length; i++) {
//Modifiers
if(k =3D=3D 'ctrl' || k =3D=3D 'control') {
kp++;
modifiers.ctrl.wanted =3D true;

} else if(k =3D=3D 'shift') {
kp++;
modifiers.shift.wanted =3D true;

} else if(k =3D=3D 'alt') {
kp++;
modifiers.alt.wanted =3D true;
} else if(k =3D=3D 'meta') {
kp++;
modifiers.meta.wanted =3D true;
} else if(k.length > 1) { //If it is a special key
if(special_keys[k] =3D=3D code) kp++;
=09
} else if(opt['keycode']) {
if(opt['keycode'] =3D=3D code) kp++;

} else { //The special keys did not match
if(character =3D=3D k) kp++;
else {
if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug =
created by using lowercase
character =3D shift_nums[character];=20
if(character =3D=3D k) kp++;
}
}
}
}
=09
if(kp =3D=3D keys.length &&=20
modifiers.ctrl.pressed =3D=3D modifiers.ctrl.wanted &&
modifiers.shift.pressed =3D=3D modifiers.shift.wanted &&
modifiers.alt.pressed =3D=3D modifiers.alt.wanted &&
modifiers.meta.pressed =3D=3D modifiers.meta.wanted) {
callback(e);
=09
if(!opt['propagate']) { //Stop the event
//e.cancelBubble is supported by IE - this will kill the bubbling =
process.
e.cancelBubble =3D true;
e.returnValue =3D false;
e.preventDefault();
=09
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return false;
}
}
}
this.all_shortcuts[shortcut_combination] =3D {
'callback':func,=20
'target':ele,=20
'event': opt['type']
};
//Attach the function with the event
if(ele.addEventListener) ele.addEventListener(opt['type'], func, =
false);
else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
else ele['on'+opt['type']] =3D func;
},

//Remove the shortcut - just specify the shortcut and I will remove the =
binding
'remove':function(shortcut_combination) {
shortcut_combination =3D shortcut_combination.toLowerCase();
var binding =3D this.all_shortcuts[shortcut_combination];
delete(this.all_shortcuts[shortcut_combination])
if(!binding) return;
var type =3D binding['event'];
var ele =3D binding['target'];
var callback =3D binding['callback'];

if(ele.detachEvent) ele.detachEvent('on'+type, callback);
else if(ele.removeEventListener) ele.removeEventListener(type, =
callback, false);
else ele['on'+type] =3D false;
}
}

</script>
<script type=3D"text/javascript">shortcut.add("Ctrl+S",function() {
alert("Hi there!");
});</script>
=09
=09
<!--<a href=3D"javascript:(function(){document.onkeypress =3D =
function(event){return event.preventDefault()}})()">Disable browser =
default behaviour!</a>-->
This page overrides the default browser behaviour for CTRL+S with a =
custom js-function.<br>
Sample Input field: <input type=3D"text">
=09
</body>

</html>
------=_NextPart_000_001E_01CA9A97.8CE50940--
Re: Key event handling in RAP [message #509122 is a reply to message #509096] Thu, 21 January 2010 13:01 Go to previous message
Rüdiger Herrmann is currently offline Rüdiger HerrmannFriend
Messages: 581
Registered: July 2009
Senior Member
On 21.01.2010 12:44, Niels Lippke wrote:
> Hmm, before I get lost in the wood. Here are my current thoughts about
> the key bindings.
>
> Attached is a sample html page containing some js-functions I found in
> the web. These functions allow the user to override the default browser
> behaviour (e.g. CTRL-S which normally open the Save As Dialog in FF and
> other browsers) with a custom function.
> Here it overides CTRL-S to open an alert window.
>
> So why not do similar in a RAP application and use those
> key-combinations for global key bindings (e.g. org.eclipse.ui.bindings)?
>
> Are there problems I don't quite grasp?
There is an enhancement request for key bindings:
282449: Keybindings in RAP
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282449
I don't see why this couldn't be achieved. However it certainly is a
non-trivial and time consuming task.

>
> Regards,
> Niels


--
Rüdiger Herrmann
http://eclipsesource.com
Previous Topic:How to start RAP from command line ?
Next Topic:How to access sessions ?
Goto Forum:
  


Current Time: Fri Nov 01 20:18:20 GMT 2024

Powered by FUDForum. Page generated in 0.02456 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top