<div class="gmail_quote">On Fri, Jan 22, 2010 at 3:47 PM, David Gobbi <span dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

It&#39;s failing because you are doing this:<br>
<br>
  rwi-&gt;GetKeySym() == &quot;Up&quot;<br>
<br>
Throw in a strcmp or something.<br>
<font color="#888888"><br>
 - David<br>
</font><div><div></div><div><br>
<br>
On Fri, Jan 22, 2010 at 1:36 PM, David Doria &lt;<a href="mailto:daviddoria%2Bvtk@gmail.com" target="_blank">daviddoria+vtk@gmail.com</a>&gt; wrote:<br>
&gt; On Fri, Jan 22, 2010 at 3:21 PM, David Gobbi &lt;<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m not sure what #defines you are talking about, but why not use the<br>
&gt;&gt; interactor &quot;GetKeySym&quot; method to detect arrow keys?  They have the<br>
&gt;&gt; names &quot;Up&quot;, &quot;Down&quot;, &quot;Left&quot;, &quot;Right&quot;.<br>
&gt;&gt;<br>
&gt;&gt;    David<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Fri, Jan 22, 2010 at 1:18 PM, David Doria &lt;<a href="mailto:daviddoria%2Bvtk@gmail.com" target="_blank">daviddoria+vtk@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt; &gt; It seems that for win32, there are some #defines for arrow keys like<br>
&gt;&gt; &gt; VK_RIGHT. I can&#39;t seem to find what should be done for non win32 - any<br>
&gt;&gt; &gt; thoughts?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; David<br>
&gt;&gt;<br>
&gt;<br>
&gt; So typically I do this from inside my InteractorStyle subclass:<br>
&gt;<br>
&gt;     virtual void OnChar()<br>
&gt;     {<br>
&gt;       vtkRenderWindowInteractor *rwi = this-&gt;Interactor;<br>
&gt;<br>
&gt;       char ch = rwi-&gt;GetKeyCode() ;<br>
&gt;       switch (ch)<br>
&gt;       {<br>
&gt;         case &#39;s&#39;:<br>
&gt;           cout &lt;&lt; &quot;Pressed s.&quot; &lt;&lt; endl;<br>
&gt;           break;<br>
&gt;         case &#39;a&#39;:<br>
&gt;           cout &lt;&lt; &quot;Pressed a.&quot; &lt;&lt; endl;<br>
&gt;           break ;<br>
&gt;         default:<br>
&gt;           cout &lt;&lt; &quot;Pressed an unhandled key: &quot; &lt;&lt; rwi-&gt;GetKeyCode() &lt;&lt; endl;<br>
&gt;           break;<br>
&gt;       }<br>
&gt; The problem is that OnChar() doesn&#39;t fire when the arrow keys are pressed. I<br>
&gt; tried to use<br>
&gt;     virtual void OnKeyDown()<br>
&gt;     {<br>
&gt;       vtkRenderWindowInteractor *rwi = this-&gt;Interactor;<br>
&gt;<br>
&gt;       if(rwi-&gt;GetKeySym() == &quot;Up&quot;)<br>
&gt;       {<br>
&gt;         cout &lt;&lt; &quot;Pressed up.&quot; &lt;&lt; endl;<br>
&gt;       }<br>
&gt;<br>
&gt;       // forward events<br>
&gt;       vtkInteractorStyleTrackballCamera::OnKeyDown();<br>
&gt;     }<br>
&gt; But it doesn&#39;t seem to compare to true. It also doesn&#39;t seem to flush the<br>
&gt; buffer when I would expect?<br>
&gt; Also, what is the difference between KeyPress and KeyDown? The documentation<br>
&gt; is kind of broken<br>
&gt; here: <a href="http://www.vtk.org/doc/nightly/html/classvtkInteractorStyle.html#a65fcd9765c162a6021434386037ca641" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkInteractorStyle.html#a65fcd9765c162a6021434386037ca641</a><br>


&gt; Thanks,<br>
&gt;<br>
&gt; David<br>
</div></div><div><div></div><div></div></div></blockquote></div><br><div>Yes, that was certainly a bug, but not as confusing as the following problem.</div><div><br></div><div>With these two functions:</div><div><br></div>
<div><div>
<br></div><div>    virtual void OnKeyPress() </div><div>    {</div><div>      vtkRenderWindowInteractor *rwi = this-&gt;Interactor;    </div><div>      </div><div>      std::string key = rwi-&gt;GetKeySym();</div><div>      if(key.compare(&quot;Up&quot;) == 0)</div>

<div>        {</div><div>        cout &lt;&lt; &quot;Pressed up.&quot; &lt;&lt; endl;</div><div>        }</div><div>      </div><div>      // forward events</div><div>      vtkInteractorStyleTrackballCamera::OnKeyPress();</div>

<div>    }</div><div>    </div><div>    virtual void OnChar() </div><div>    {</div><div>      vtkRenderWindowInteractor *rwi = this-&gt;Interactor;<span style="white-space:pre">                </span></div><div>
        </div><div>      char ch = rwi-&gt;GetKeyCode() ;</div><div><br></div><div>      switch (ch) </div><div>      {</div><div>        case &#39;s&#39;:</div><div>          cout &lt;&lt; &quot;Pressed s.&quot; &lt;&lt; endl;</div>

<div>          break;</div><div>        case &#39;a&#39;:</div><div>          cout &lt;&lt; &quot;Pressed a.&quot; &lt;&lt; endl;</div><div>          break ;</div><div>        default:</div><div>          cout &lt;&lt; &quot;Pressed an unhandled key: &quot; &lt;&lt; ch &lt;&lt; endl;</div>

<div>          break;</div><div>      }</div><div><span style="white-space:pre">        </span></div><div><span style="white-space:pre">                </span>  // forward events</div><div>      vtkInteractorStyleTrackballCamera::OnChar();</div>

<div>    }</div><div><br></div><div>The output of pressing:</div></div><div>a, b, up, a</div><div><br></div><div>Is: </div><div><br></div><div><div>Pressed a.</div><div>Pressed an unhandled key: b</div><div>Pressed up.</div>

<div>Pressed an unhandled key: Pressed a.</div><div><br></div><div>You can see that there is an &quot;unhandled key&quot; in the mix when there was actually no unhandled key. There were only 4 keypresses, and 5 outputs.</div>
<div>
<br></div>Thanks,<br><br>David</div>