View Full Version : help with double keypress event

27 Jan 2010, 10:30 PM
Hi all, may you all pls give me some help with how to writing a double kepress event.

I want to erase few textfields' value when user press "ESC" twice. I should use EventManager addListener or override KeyMap's addBinding to support "esc: true" ???

28 Jan 2010, 7:51 AM
Sounds like you want to "count" the number of times a user presses a certain key (in this case the esc key) and handle the event if it happens two times.

I'd suggest using the callback to count the number of times a user presses the escape key. Then check if the counter is at the limit. If so, handle it and then reset the counter.

var escCounter = 0; // initialize the counter
var map = new Ext.KeyMap(document, {
key: Ext.EventObject.ESC // listen for escape keydown
,fn: function () {
escCounter++; // increment counter
if (escCounter == 2) { // check if counter is at limit
alert('two escapes were pressed'); // handle the event
escCounter = 0; // reset the counter
,scope: this
Hope that helps.

29 Jan 2010, 5:50 PM
Maybe the words is not clear. Actually, what I want to do is, some-like a double click function. Single press, call functionA; Double press(in a short time, else, treat as 2 single press) call function B. Your code isn't quite suitable in my case.

1 Feb 2010, 9:11 AM
hmmm... can't help you there.

A keypress and double-keypress handler on a textfield? That sounds like trouble for the user. Maybe you should re-think the UI; A key-combo instead of a double-keypress seems like a sensible alternative. Why not use ctrl + esc

4 Feb 2010, 7:49 PM
esc makes current textfield clear while double-esc makes all textfields clear, sound quite reasonable and is of our practices...

<ctrl>+<ecs> would end up openning a start menu in windows case, so this doesn't suit my case...If you say I could use say <shift>+<esc> or <tab>+<esc>, well, I think this doesn't quite make sense...

any other help? I really want to do a double keypress event....:(:(