C++ Integration - forwarding keyboard inputs
Posted: 07 Oct 2019, 05:39
I'm a beginner at this so bear with me. I was using one of the projects that come with the Noesis SDK: IntegrationGLUT. I added a keyboard handler through the existing glut.h mechanisms (WndProc, WM_KEYDOWN, WM_KEYUP) and called view->KeyDown and view->KeyUp as inputs came in. I added a TextBox but as I typed nothing showed up except space and backspace. I started calling view->Char in addition to KeyDown and then characters started showed up in the TextBox. The real problem is that if I hit Backspace on the TextBox, then the next alphanumeric key I type doesn't show up. After a backspace I had to call view->Char(inputChar) twice with whatever is typed next for it to show up. Here's my handler:
The SDK documentation has basically two short sentences with an ambigous explanation of KeyUp/Down/Char in Noesis Integration Tutorial:
Code: Select all
int lastCharSent = -1;
////////////////////////////////////////////////////////////////////////////////////////////////////
static void KeyFunc(int key, int state)
{
Noesis::Key nKey = (Noesis::Key) WINAPI_KEYMAPPING[key]; // get the Noesis key code from the WinApi value (like 0x41 = Noesis::Key_A)
if (state == GLUT_DOWN)
{
int ProcChar = TranslateKey(key); // turn the input key into a char (i.e. "a" instead of 0x41)
if (ProcChar != 0) {
_view->Char((uint32_t)ProcChar);
if (lastCharSent == Key_Back) // HACK to overcome Char eating character sent after a backspace
_view->Char((uint32_t)ProcChar);
}
_view->KeyDown(nKey);
lastCharSent = (int)nKey;
}
else
_view->KeyUp(nKey);
}
Those two sentences don't really explain the behavior I'm seeing. What am I doing wrong?When a key is pressed you must use KeyDown() and KeyUp(). To send already processed UTF-32 characters, Char is provided.