[vtkusers] OnKeyRelease...[SOLVED...i think]

Matt Schmiermund matt at plasticflow.com
Wed Jun 2 14:01:29 EDT 2004


I couldn't figure out why the OnKeyRelease was never
being called, until I was looking through some source
code I ran into my vtkQt folder and it dawned on my
that Koenig's vtkQtRenderWindowInteractor might not be
handling the keyReleaseEvent properly. I looked in the
code and sure enough, no functions for key releases.

In vtkQtRenderWindowInteractor.cpp I added this
function:

void
vtkQtRenderWindowInteractor::keyReleaseEvent(QKeyEvent
*ke) {
	if (!Enabled)
        return;
    
    qtRenWin->GetSize(Size[0], Size[1]);
	int ctrl = 0, shift = 0;

    QPoint cp =
qtRenWin->mapFromGlobal(QCursor::pos());
    int xp = cp.x();
    int yp = cp.y();
    SetEventInformationFlipY(xp, yp, ctrl, shift,
(char) tolower(ke->ascii()), 1, (const char *)
ke->text());
    InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
    
}

Not sure that all of it is necessary. I copied most of
what was in keyPressEvent, but it appears to work.

And then to vtkQtRenderWindow.cpp I added the
function:

void vtkQtRenderWindow::keyReleaseEvent( QKeyEvent
*ke) {
   if (qtRenWinInt)
     qtRenWinInt->keyReleaseEvent(ke);
}


And made the appropriate changes to the .h files,
recompiled and my program is now getting the
keyReleaseEvents.

Thanks to those of you that offered help.

-Matt Schmiermund

--- Andrew Dolgert <ajd27 at cornell.edu> wrote:
> Hi Matt,
> 
> Windows has fires two events for a key down: 
> WM_KEYDOWN, and then WM_CHAR
> or WM_UNICHAR.  It then fires WM_KEYUP when the key
> is released.  The VTK
> interactor turns a KEYDOWN into a KeyPress event,
> KEYUP into a KeyRelease
> event, and WM_CHAR into a CharEvent.
> 
> I turned on debugging for the interactor, and it
> shows that, during a
> WM_KEYUP event, something queries the interactor for
> the value of the key (I
> was releasing 'b').  It seems to me that the key
> release worked.
> 
> If you are using .NET, then you are sending events
> to VTK by hand.  I found
> some code of mine where, for some unknown reason, I
> didn't send every event
> to VTK.  I used a case statement instead, and it
> would be easy to miss the
> WM_KEYUP event in that case statement.  Did you do
> this and forget to
> include WM_KEYUP?  See the code below.
> 
> I can't be the only one who made a pure managed C++
> Windows::Forms::UserControl in order to use VTK from
> C#.  We should just
> have an example.
> 
> - Drew
> 
> void FEMViewControl::DefWndProc(
> System::Windows::Forms::Message* msg)
> {
>   int msgType = msg->get_Msg();
>   switch ( msgType ) {
>     case WM_CHAR:
>       System::Diagnostics::Debug::WriteLine("char");
>       break;
>     case WM_KEYDOWN:
>       System::Diagnostics::Debug::WriteLine("key
> down");
>       break;
>     case WM_KEYUP:
>       System::Diagnostics::Debug::WriteLine("key
> up");
>       break;
>   }
> 
>   switch ( msgType ) {
>         case WM_LBUTTONDOWN:
>         case WM_LBUTTONUP:
>         case WM_MBUTTONDOWN:
>         case WM_MBUTTONUP:
>         case WM_RBUTTONDOWN:
>         case WM_RBUTTONUP:
>         case WM_MOUSEMOVE:
>         case WM_CHAR:
>         case WM_KEYDOWN:
>         case WM_KEYUP:
>         case WM_TIMER:
> 	int lresult = 0;
> 	  if ( 0 != m_interactor->GetInitialized() )
>   	{
>   	  lResult = ::vtkHandleMessage2(
>   	    (HWND) msg->get_HWnd().ToPointer(),
>   	    msg->get_Msg(),
>   	    (WPARAM) msg->get_WParam().ToPointer(),
>   	    (LPARAM) msg->get_LParam().ToPointer(),
>   	    m_interactor );
>   	}
>   }
> 
>   __super::DefWndProc( msg );
> }
> 




More information about the vtkusers mailing list