[vtk-developers] vtkWidgetEventTranslator -- care and feeding?
karthik.krishnan at kitware.com
Thu Dec 20 12:19:35 EST 2007
On 12/20/07, kent williams <nkwmailinglists at gmail.com> wrote:
> Hee. One last thing -- you Set a callback both for KeyPressEvent and
> CharEvent, and the result is hitting the Delete key once ends up
> deleting 2 points. The patch I sent commented out the second
> SetCallbackMethod, but you left both in.
Was there a reason to have a callback on both events? It doesn't
> appear to produce the behavior documented in Doxygen.
Ah yes.. Keeping the KeyPressEvent alone will suffice.
Funny, I didn't see the bug. If you ran your code on windows, you would've
noticed that only 1 point was deleted :)
So I asked myself, why are there two events,
and why are they both emmitted.... After some snooping, here's why:
In windows, when a key is pressed, you get a WM_KEYDOWN message. You can get
access to the pressed key with its virtual key code.
Apart from this, as messages get translated by the TranslateMessage() Win32
function, they are checked with the current keyboard config, and an
additional WM_CHAR message is sent for each WM_KEYDOWN, with the
current-codepage character code of the key pressed.
Now, for ASCII characters like "a" etc, both events are emmitted. For the
special characters like "Delete", arrow keys etc, only the KeyPressEvent is
emmitted. The reason is that there is no alphanumeric character
representation of these keys.
The advantage that WM_CHAR gives that WM_KEYPRESS doesn't is the translation
of the message. So on non-US keyboards, representing accents etc, WM_CHAR
would provide the correct translation for accent keys etc, which WM_KEYPRESS
woundn't.... On mobile devices where there's more than one character mapped
to the same key, WM_CHAR would return the actual key press.
For non-windows people they shouldn't even bother about the CharEvent.
I guess the conclusion is that for all practical VTK purposes, its safe to
use the KeyPress event, unless somebody complains about it..
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the vtk-developers