[vtkusers] KeyDown vs KeyPress events

David Gobbi david.gobbi at gmail.com
Tue Jan 26 14:16:01 EST 2010


On Tue, Jan 26, 2010 at 11:55 AM, David Doria <daviddoria+vtk at gmail.com> wrote:
> The other day we were discussing the difference between KeyPress and
> KeyDown. I found this about Java key events - I'd imagine it's the
> same for VTK?
>
> "In order to understand the difference between keydown and keypress,
> it is useful to understand the difference between a "character" and a
> "key". A "key" is a physical button on the computer's keyboard while a
> "character" is a symbol typed by pressing a button.  In theory, the
> keydown and keyup events represent keys being pressed or released,
> while the keypress event represents a character being typed."
>
> "The keydown event occurs when the key is pressed, followed
> immediately by the keypress event. Then the keyup event is generated
> when the key is released."
>
> There is also an OnChar and an OnRelease though
> (http://www.vtk.org/doc/nightly/html/classvtkInteractorStyle.html#a4c557c1b61499380973316ccc22efaae),
> so I'm not sure where those fit in.
>
> Can anyone confirm the above and clarify these additional functions?
> Once we get them cleared up, I'll fix the documentation.
>
> Thanks,
>
> David

Hi David,

In VTK there is no difference between KeyDown and KeyPress.  No
difference at all.  Every KeyPressEvent should be accompanied by a
KeyDownEvent and vice versa.  For every OnKeyDown, an OnKeyPress.  The
"KeyDown" name is from Windows and "KeyPress" is from X11/Tcl and I
guess that whoever wrote the InteractorStyle class just wanted to be
inclusive.

What you were reading about Java's KeyDown is actually what VTK's
CharEvent is for.  It should go without saying that the Java
documentation does not apply to VTK.

KeyPress/KeyDown -> any key is pressed
KeyRelease -> any key is released
Char -> one or more characters generated by a key press (maybe a
printing character, but not always).

   David



More information about the vtkusers mailing list