(Please forgive my shorthand as this is from memory) I have code similar to:
bool myclass::handle(event ea){
switch (ea.getEventType()){
case(osgGA::KEYDOWN):
switch (ea.getkey() )
{
case (osgGA::KEY_Lshift):
down = true;
break;
case (osgGA::KEY_W):
forward = true;
break;
}
return false;
case(osgGA::KEYUP){
switch (ea.getkey() )
{
case (osgGA::KEY_Lshift):
down = false;
break;
case (osgGA::KEY_W):
forward = false;
break;
}
return false;
}
I print the ea.getkey() and when I press 'w', I get the expected behavior of it moving forward. However, if I press 'shift' next and then let go of 'w', I get my debug: "KEYUP: W". Note that it's capitalized, and I continue to move forward until a lowercase 'w' is pressed and released.
Am I expected to just use basic C++ functions to convert everything to lowercase? I'm just trying to use standard WASD movement with Space/L-shift as move up and down around my environment.
When you press a key, osg creates an event with the corresponding key code, which is different for a letter or its corresponding capitalized one.
osgGA::KEY_W
it's simply an enum value corresponding to the lower case 'w' (119 ascii code), while 'W' has code 87.
So if you want to get either the lower or upper case keypress, simply write something like:
if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN)
{
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_W || ea.getKey() == 'W')
{ /*code when either w or W is pressed*/ }
}