02-25-2020 10:36 AM
I'm trying to capture messages from the keyboard in my CVI application regardless of where the user touched the screen. I found an article on using the raw input API to do this. I made the call to RegisterRawInputDevices to tell Windows to send raw input to my CVI program. That seemed to work correctly. Then I called InstallWinMsgCallback to setup my callback function for WM_INPUT messages. When the program runs I hit keys on the keyboard but my callback never gets called. I'm not sure if the issue is with the way I'm registering the raw input or with the way I setup the WM_INPUT callback. Code snippets are below. Any suggestions on how to figure out what's going wrong would be appreciated.
In main:
WindowsHandle = GetCVIWindowHandle();
RAWINPUTDEVICE RawInputDevice[1];
RawInputDevice[0].dwFlags = RIDEV_NOLEGACY|RIDEV_INPUTSINK;
RawInputDevice[0].usUsagePage = 0x01;
RawInputDevice[0].usUsage = 0x06;
RawInputDevice[0].hwndTarget = WindowsHandle;
if (RegisterRawInputDevices(RawInputDevice, 1, sizeof(RawInputDevice[0])) == FALSE)
{
MessagePopup("Crap!", "Didn't register");
Error = GetLastError();
} /* if-then */
else
{
MessagePopup("Yes!", "Success");
} /* if-else */
intptr_t TempHandle;
if ((stat = InstallWinMsgCallback (panelHandle, WM_INPUT, MainPnlMsgCallback, VAL_MODE_IN_QUEUE, NULL, &TempHandle)))
{
MessagePopup ("Error", GetGeneralErrorString (stat));
}
My callback:
int CVICALLBACK MainPnlMsgCallback (int panelHandle,
int message,
unsigned int* wParam,
unsigned int* lParam,
void* callbackData)
{
/* Pay attention if our Windows handle was changed... */
if (message == EVENT_NEWHANDLE)
{
MessagePopup ("","New handle!!!");
}
else
{
char Buff[100];
sprintf(Buff,"msg=%d", message);
}
return 0;
}