<div>On Fri, Jan 22, 2010 at 4:17 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>></span> wrote:</div><div class="gmail_quote"><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 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>
</div></div>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>
<font color="#888888"><br>
David<br>
</font></blockquote></div><div><br></div>Yea, I just though of that in the car :)<div><br></div><div>Using a single function does just fine:</div><div><br><div><div> virtual void OnKeyPress() </div><div> {</div><div>
//get the keypress</div><div> vtkRenderWindowInteractor *rwi = this->Interactor;</div><div> std::string key = rwi->GetKeySym();</div><div> </div><div> //output the key that was pressed</div>
<div> cout << "Pressed " << key << endl;</div><div> </div><div> //handle an arrow key</div><div> if(key.compare("Up") == 0)</div><div> {</div><div> cout << "The up arrow was pressed." << endl;</div>
<div> }</div><div> </div><div> //handle a "normal" key</div><div> if(key.compare("a") == 0)</div><div> {</div><div> cout << "The a key was pressed." << endl;</div>
<div> }</div><div> </div><div> // forward events</div><div> vtkInteractorStyleTrackballCamera::OnKeyPress();</div><div> }</div><div><br></div><div>So two questions remain - 1) What is the difference between OnKeyPress and OnKeyDown? 2) Why/when to use OnChar when OnKeyPress seems to be more general?</div>
<div><br></div>Thanks for the help,<br><br>David</div></div>