Friday, June 24, 2011

Key events of web browser KeyEvents

One area of Web Edition which has been confusing to our users has been the data that is returned from a user's browser with the two keyboard events — KeyDown and KeyUp. In Real Studio 2011r2, we've changed some things around to make the data more consistent from browser to browser and simpler to implement.

First of all, instead of two events, there is now only one, KeyPressed. This event fires after a key has been pressed and the Details parameter now includes several more pieces of information:
  • 4 Booleans that indicate the state of the different meta keys — AltKey, CtrlKey, MetaKey and ShiftKey.
  • Character contains the character that the user typed, assuming the key that was pressed has a glyph associated with it.
  • CharCode contains the ascii character code associated with the key.
  • KeyCode contains the keyboard code associated with the key (note: this may be different than CharCode, but not always). 28 KeyCode Constants to help you figure out which non-character key has been pressed.
Note: Some browsers even include the key names in the Character property. For instance, if you pressed the down arrow key, Character might be set to "Down". Don't rely on this functionality, it's not consistent from browser to browser.


Bad_Wolf said...

Hi All,

I really do not see how people can be confused by the events "KeyDown" and "KeyUp".

KeyDown fires when pressing a keyboard key, KeyUp fires when you release a key.

In a few instances I used KeyUp but mostly if not always I use KeyDown. Last time I used KeyUp I had to let the KeyDown event returning "True" otherwise the KeyUp event will do nothing.

I agree that the newly "KeyPressed" event is much more powerfull but personally for the desktop version, I prefer keeping KeyDown and KeyUp, but this is a personal preference. In case the KeyPressed event comes to the desktop version too, I will adapt my programing behaviour accordingly.

To the RealStudio team; very nice job done with the r2 release, thank you very much!

Have a very nice day.

Friendly greetings,


Greg O'Lone said...

This change only affects Web Edition. Desktop applications can still use the KeyUp and KeyDown events.