<div><div class="gmail_quote">On Mon, Jan 25, 2010 at 4:18 AM, Liam Kurmos <span dir="ltr"><<a href="mailto:quantum.leaf@googlemail.com">quantum.leaf@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Fri, Jan 22, 2010 at 9:17 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br>
> On Fri, Jan 22, 2010 at 2:06 PM, David Doria <<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>> wrote:<br>
>> On Fri, Jan 22, 2010 at 3:47 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br>
>>><br>
>>> It's failing because you are doing this:<br>
>>><br>
>>> rwi->GetKeySym() == "Up"<br>
>>><br>
>>> Throw in a strcmp or something.<br>
>>><br>
>>> - David<br>
>>><br>
>>><br>
>>> On Fri, Jan 22, 2010 at 1:36 PM, David Doria <<a href="mailto:daviddoria%2Bvtk@gmail.com">daviddoria+vtk@gmail.com</a>><br>
>>> wrote:<br>
>>> > On Fri, Jan 22, 2010 at 3:21 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>><br>
>>> > 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">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 -<br>
>>> >> > 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() <<<br>
>>> > endl;<br>
>>> > break;<br>
>>> > }<br>
>>> > The problem is that OnChar() doesn't fire when the arrow keys are<br>
>>> > 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<br>
>>> > the<br>
>>> > buffer when I would expect?<br>
>>> > Also, what is the difference between KeyPress and KeyDown? The<br>
>>> > documentation<br>
>>> > is kind of broken<br>
>>> ><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>
>><br>
>> Yes, that was certainly a bug, but not as confusing as the following<br>
>> problem.<br>
>> With these two functions:<br>
>><br>
>> virtual void OnKeyPress()<br>
>> {<br>
>> vtkRenderWindowInteractor *rwi = this->Interactor;<br>
>><br>
>> std::string key = rwi->GetKeySym();<br>
>> if(key.compare("Up") == 0)<br>
>> {<br>
>> cout << "Pressed up." << endl;<br>
>> }<br>
>><br>
>> // forward events<br>
>> vtkInteractorStyleTrackballCamera::OnKeyPress();<br>
>> }<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: " << ch << endl;<br>
>> break;<br>
>> }<br>
>> // forward events<br>
>> vtkInteractorStyleTrackballCamera::OnChar();<br>
>> }<br>
>> The output of pressing:<br>
>> a, b, up, a<br>
>> Is:<br>
>> Pressed a.<br>
>> Pressed an unhandled key: b<br>
>> Pressed up.<br>
>> Pressed an unhandled key: Pressed a.<br>
>> You can see that there is an "unhandled key" in the mix when there was<br>
>> actually no unhandled key. There were only 4 keypresses, and 5 outputs.<br>
>> Thanks,<br>
>><br>
>> David<br>
><br>
> Print out the keycode of the mystery key as a hexidecimal value. My<br>
> guess is that you're seeing an output from the arrow key in both the<br>
> OnKeyPress and in OnChar. The KeyCode values aren't guaranteed to be<br>
> ascii.<br>
><br>
> David<br>
<br>
</div></div>off topic, but I found it interesting to learn that sending a<br>
non-ascii char to cout can cause the <<endl not to function without<br>
throwing an error.<br>
<font color="#888888"><br>
Liam<br>
</font><div><div></div><div class="h5"></div></div></blockquote></div><br></div><div>I can confirm that behavior. That was part of my initial confusion.<div><br clear="all">Thanks,<br><br>David</div></div>