Justin Ellis | 8 Jun 2012 02:52
Picon

Shift key only fires onkeydown event when it is released?

Hi all,

Somewhat related to my last, invalid question since I am trying to
make a grid recognize shift+key combos.  The problem is that, when I
catch an onkeydown event in my grid and check to see if the shift key
is down using "lz.Keys.isKeyDown('shift')", the first time I try it
with the shift key down the "isKeyDown" method returns "false," and
then only returns "true" if I keep the shift key down and enter in
subsequent key presses.  To test, I added an "onkeydown" handler in my
canvas that looks like this:

<handler name="onkeydown" reference="lz.Keys" args="kc">
	Debug.write("Key: " + kc);
</handler>

Here is what happens:

<I press the "Shift" key> - Nothing happens
<I release the "Shift key> - Debug Message: "Key: 16"
<I press the "Shift" key> - Nothing happens
<I press the "Down Arrow" key> - Debug Message: "Key 40", Debug
Message: "Key 16"
<I release and then press the "Down Arrow" key again> - Debug Message: "Key 40"

So basically the lz.Keys object does not register when "Shift" is
pressed until either (a) "Shift" is lifted, or (b) Another key is
pressed, at which time it registers the "Shift" press *after* the
other key is pressed, so a handler catching that key press will return
false for "lz.Keys.isKeyDown('shift')".

(Continue reading)

Picon
Gravatar

Re: Shift key only fires onkeydown event when it is released?

Hi Justin,

the same problem persists if you for example have key combos with multiple keys and then suddenly change the focus to another application on your desktop (for example with Alt+Tab).

There is not fix for that, it is a problem related to the Flash Player from my point of view. You simply can't rely on getting all keyUpEvents 100%.

You can however possibly workaround that if you concentrate on the keydown events only. For example you implement a listener for onkeydown events and then add a listener for xxx milliseconds listening if another keydown was called in that period. If yes, you can trigger your key-combo-event, if no you just clear the keyDownArray. That way you don't need any keyUpEvent at all.

Sebastian



2012/6/8 Justin Ellis <ellisju-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Hi all,

Somewhat related to my last, invalid question since I am trying to
make a grid recognize shift+key combos.  The problem is that, when I
catch an onkeydown event in my grid and check to see if the shift key
is down using "lz.Keys.isKeyDown('shift')", the first time I try it
with the shift key down the "isKeyDown" method returns "false," and
then only returns "true" if I keep the shift key down and enter in
subsequent key presses.  To test, I added an "onkeydown" handler in my
canvas that looks like this:

<handler name="onkeydown" reference="lz.Keys" args="kc">
       Debug.write("Key: " + kc);
</handler>

Here is what happens:

<I press the "Shift" key> - Nothing happens
<I release the "Shift key> - Debug Message: "Key: 16"
<I press the "Shift" key> - Nothing happens
<I press the "Down Arrow" key> - Debug Message: "Key 40", Debug
Message: "Key 16"
<I release and then press the "Down Arrow" key again> - Debug Message: "Key 40"

So basically the lz.Keys object does not register when "Shift" is
pressed until either (a) "Shift" is lifted, or (b) Another key is
pressed, at which time it registers the "Shift" press *after* the
other key is pressed, so a handler catching that key press will return
false for "lz.Keys.isKeyDown('shift')".

Is there any way to fix this?

--
Justin Ellis
646-783-9387
Fax: 866-448-6503
ellisju-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
www.LightBulbLaw.com



--
Sebastian Wagner
https://twitter.com/#!/dead_lock
http://www.openmeetings.de
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Justin Ellis | 9 Jun 2012 18:38
Picon

Re: Shift key only fires onkeydown event when it is released?

Seba,

This is not a problem with the Flash engine, as I am running under the
DHTML runtime.  This is definitely a problem with the keyboard kernel.
 Also, if you read the description, the problem is with the keyboard
down events, not keyboard up events.  I have found that it works the
same way with the alt and control keys as well.  With the
functionality the way it is, there is simply no way to write your app
so that it can distinguish between a button being pressed by itself
and a button being pressed as a combination.  Sure, you will
eventually get the combination event, or the keydown event for the
shift, control or alt keys, but not until *after* you get the keydown
event for the other key that is being pressed, so you cannot tell your
app "do one thing if this key is pressed, but do something different
if this key is pressed in combination with the shift key".

You can easily see this in action with any implementation of the grid
object.  Hit "tab" a few times to focus on subsequent cells, and then
start hitting "shift + tab" combination; the first time you hit shift
+ tab, the grid will go on to the *next* focus, and only on subsequent
presses will it start focusing *previous* elements like it is supposed
to.

Even easier, you can write a handler for all keyboard down events from
lz.Keys and output the keycode to the debug console.  You will see
that the shift, control and alt keys do not fire a keydown event until
the key is lifted, while every other key on the keyboard fires a down
event right when it is depressed.

I think this is a browser-specific issue, because I am using Chrome
but if I use Firefox the events do fire when the key goes down.
However, using the method above, I can see that even though the shift
key fires the first time you press it down in Firefox, it does not
fire on subsequent presses until you hit another button.  Apparently
the keyboard kernel is simply messed up.

I would open a problem ticket on this, but official support for OL
seems to have all but vanished.

J

On Sat, Jun 9, 2012 at 2:15 AM, seba.wagner@...
<seba.wagner@...> wrote:
> Hi Justin,
>
> the same problem persists if you for example have key combos with multiple
> keys and then suddenly change the focus to another application on your
> desktop (for example with Alt+Tab).
>
> There is not fix for that, it is a problem related to the Flash Player from
> my point of view. You simply can't rely on getting all keyUpEvents 100%.
>
> You can however possibly workaround that if you concentrate on the keydown
> events only. For example you implement a listener for onkeydown events and
> then add a listener for xxx milliseconds listening if another keydown was
> called in that period. If yes, you can trigger your key-combo-event, if no
> you just clear the keyDownArray. That way you don't need any keyUpEvent at
> all.
>
> Sebastian
>
>
>
>
> 2012/6/8 Justin Ellis <ellisju@...>
>>
>> Hi all,
>>
>> Somewhat related to my last, invalid question since I am trying to
>> make a grid recognize shift+key combos.  The problem is that, when I
>> catch an onkeydown event in my grid and check to see if the shift key
>> is down using "lz.Keys.isKeyDown('shift')", the first time I try it
>> with the shift key down the "isKeyDown" method returns "false," and
>> then only returns "true" if I keep the shift key down and enter in
>> subsequent key presses.  To test, I added an "onkeydown" handler in my
>> canvas that looks like this:
>>
>> <handler name="onkeydown" reference="lz.Keys" args="kc">
>>        Debug.write("Key: " + kc);
>> </handler>
>>
>> Here is what happens:
>>
>> <I press the "Shift" key> - Nothing happens
>> <I release the "Shift key> - Debug Message: "Key: 16"
>> <I press the "Shift" key> - Nothing happens
>> <I press the "Down Arrow" key> - Debug Message: "Key 40", Debug
>> Message: "Key 16"
>> <I release and then press the "Down Arrow" key again> - Debug Message:
>> "Key 40"
>>
>> So basically the lz.Keys object does not register when "Shift" is
>> pressed until either (a) "Shift" is lifted, or (b) Another key is
>> pressed, at which time it registers the "Shift" press *after* the
>> other key is pressed, so a handler catching that key press will return
>> false for "lz.Keys.isKeyDown('shift')".
>>
>> Is there any way to fix this?
>>
>> --
>> Justin Ellis
>> 646-783-9387
>> Fax: 866-448-6503
>> ellisju@...
>> www.LightBulbLaw.com
>
>
>
>
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.openmeetings.de
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner@...

--

-- 
Justin Ellis
646-783-9387
Fax: 866-448-6503
ellisju@...
www.LightBulbLaw.com

Picon
Gravatar

Re: Shift key only fires onkeydown event when it is released?

I guess you're using openlaszlo 5.x. I don't think that any version before 5.x will receive any update or fix anymore. Otherwise your only chance to fix that is either to implement it in your own logic or trying to fix the existing API by buildign OpenLaszlo from source.

Sebastian

2012/6/9 Justin Ellis <ellisju-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Seba,

This is not a problem with the Flash engine, as I am running under the
DHTML runtime.  This is definitely a problem with the keyboard kernel.
 Also, if you read the description, the problem is with the keyboard
down events, not keyboard up events.  I have found that it works the
same way with the alt and control keys as well.  With the
functionality the way it is, there is simply no way to write your app
so that it can distinguish between a button being pressed by itself
and a button being pressed as a combination.  Sure, you will
eventually get the combination event, or the keydown event for the
shift, control or alt keys, but not until *after* you get the keydown
event for the other key that is being pressed, so you cannot tell your
app "do one thing if this key is pressed, but do something different
if this key is pressed in combination with the shift key".

You can easily see this in action with any implementation of the grid
object.  Hit "tab" a few times to focus on subsequent cells, and then
start hitting "shift + tab" combination; the first time you hit shift
+ tab, the grid will go on to the *next* focus, and only on subsequent
presses will it start focusing *previous* elements like it is supposed
to.

Even easier, you can write a handler for all keyboard down events from
lz.Keys and output the keycode to the debug console.  You will see
that the shift, control and alt keys do not fire a keydown event until
the key is lifted, while every other key on the keyboard fires a down
event right when it is depressed.

I think this is a browser-specific issue, because I am using Chrome
but if I use Firefox the events do fire when the key goes down.
However, using the method above, I can see that even though the shift
key fires the first time you press it down in Firefox, it does not
fire on subsequent presses until you hit another button.  Apparently
the keyboard kernel is simply messed up.

I would open a problem ticket on this, but official support for OL
seems to have all but vanished.


J

On Sat, Jun 9, 2012 at 2:15 AM, seba.wagner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
<seba.wagner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Hi Justin,
>
> the same problem persists if you for example have key combos with multiple
> keys and then suddenly change the focus to another application on your
> desktop (for example with Alt+Tab).
>
> There is not fix for that, it is a problem related to the Flash Player from
> my point of view. You simply can't rely on getting all keyUpEvents 100%.
>
> You can however possibly workaround that if you concentrate on the keydown
> events only. For example you implement a listener for onkeydown events and
> then add a listener for xxx milliseconds listening if another keydown was
> called in that period. If yes, you can trigger your key-combo-event, if no
> you just clear the keyDownArray. That way you don't need any keyUpEvent at
> all.
>
> Sebastian
>
>
>
>
> 2012/6/8 Justin Ellis <ellisju <at> gmail.com>
>>
>> Hi all,
>>
>> Somewhat related to my last, invalid question since I am trying to
>> make a grid recognize shift+key combos.  The problem is that, when I
>> catch an onkeydown event in my grid and check to see if the shift key
>> is down using "lz.Keys.isKeyDown('shift')", the first time I try it
>> with the shift key down the "isKeyDown" method returns "false," and
>> then only returns "true" if I keep the shift key down and enter in
>> subsequent key presses.  To test, I added an "onkeydown" handler in my
>> canvas that looks like this:
>>
>> <handler name="onkeydown" reference="lz.Keys" args="kc">
>>        Debug.write("Key: " + kc);
>> </handler>
>>
>> Here is what happens:
>>
>> <I press the "Shift" key> - Nothing happens
>> <I release the "Shift key> - Debug Message: "Key: 16"
>> <I press the "Shift" key> - Nothing happens
>> <I press the "Down Arrow" key> - Debug Message: "Key 40", Debug
>> Message: "Key 16"
>> <I release and then press the "Down Arrow" key again> - Debug Message:
>> "Key 40"
>>
>> So basically the lz.Keys object does not register when "Shift" is
>> pressed until either (a) "Shift" is lifted, or (b) Another key is
>> pressed, at which time it registers the "Shift" press *after* the
>> other key is pressed, so a handler catching that key press will return
>> false for "lz.Keys.isKeyDown('shift')".
>>
>> Is there any way to fix this?
>>
>> --
>> Justin Ellis
>> 646-783-9387
>> Fax: 866-448-6503
>> ellisju-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
>> www.LightBulbLaw.com
>
>
>
>
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.openmeetings.de
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org



--
Justin Ellis
646-783-9387
Fax: 866-448-6503
ellisju-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
www.LightBulbLaw.com



--
Sebastian Wagner
https://twitter.com/#!/dead_lock
http://www.openmeetings.de
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

Gmane