<div class="gmail_quote">On Fri, Jan 22, 2010 at 3:47 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It's failing because you are doing this:<br>
<br>
rwi->GetKeySym() == "Up"<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 <<a href="mailto:daviddoria%2Bvtk@gmail.com" target="_blank">daviddoria+vtk@gmail.com</a>> wrote:<br>
> On Fri, Jan 22, 2010 at 3:21 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> wrote:<br>
>><br>
>> I'm not sure what #defines you are talking about, but why not use the<br>
>> interactor "GetKeySym" method to detect arrow keys? They have the<br>
>> names "Up", "Down", "Left", "Right".<br>
>><br>
>> David<br>
>><br>
>><br>
>> On Fri, Jan 22, 2010 at 1:18 PM, David Doria <<a href="mailto:daviddoria%2Bvtk@gmail.com" target="_blank">daviddoria+vtk@gmail.com</a>><br>
>> wrote:<br>
>> > It seems that for win32, there are some #defines for arrow keys like<br>
>> > VK_RIGHT. I can't seem to find what should be done for non win32 - any<br>
>> > thoughts?<br>
>> ><br>
>> > Thanks,<br>
>> ><br>
>> > David<br>
>><br>
><br>
> So typically I do this from inside my InteractorStyle subclass:<br>
><br>
> virtual void OnChar()<br>
> {<br>
> vtkRenderWindowInteractor *rwi = this->Interactor;<br>
><br>
> char ch = rwi->GetKeyCode() ;<br>
> switch (ch)<br>
> {<br>
> case 's':<br>
> cout << "Pressed s." << endl;<br>
> break;<br>
> case 'a':<br>
> cout << "Pressed a." << endl;<br>
> break ;<br>
> default:<br>
> cout << "Pressed an unhandled key: " << rwi->GetKeyCode() << endl;<br>
> break;<br>
> }<br>
> The problem is that OnChar() doesn't fire when the arrow keys are pressed. I<br>
> tried to use<br>
> virtual void OnKeyDown()<br>
> {<br>
> vtkRenderWindowInteractor *rwi = this->Interactor;<br>
><br>
> if(rwi->GetKeySym() == "Up")<br>
> {<br>
> cout << "Pressed up." << endl;<br>
> }<br>
><br>
> // forward events<br>
> vtkInteractorStyleTrackballCamera::OnKeyDown();<br>
> }<br>
> But it doesn't seem to compare to true. It also doesn't seem to flush the<br>
> buffer when I would expect?<br>
> Also, what is the difference between KeyPress and KeyDown? The documentation<br>
> is kind of broken<br>
> 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>
> Thanks,<br>
><br>
> 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->Interactor; </div><div> </div><div> std::string key = rwi->GetKeySym();</div><div> if(key.compare("Up") == 0)</div>
<div> {</div><div> cout << "Pressed up." << 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->Interactor;<span style="white-space:pre">                </span></div><div>
</div><div> char ch = rwi->GetKeyCode() ;</div><div><br></div><div> switch (ch) </div><div> {</div><div> case 's':</div><div> cout << "Pressed s." << endl;</div>
<div> break;</div><div> case 'a':</div><div> cout << "Pressed a." << endl;</div><div> break ;</div><div> default:</div><div> cout << "Pressed an unhandled key: " << ch << 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 "unhandled key" 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>