Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you identify a key events source (std keyboard or a USB barcode reader emulating keyboard)?

I have attached a USB barcode reader which essentially emulates a USB
keyboard. Having looked through the VC++ V5.0 documentation and some SDK
documents that I have, I could not find a library function that identifies
what device sourced the keyboad event.

Does know if this is possible ? Anyone have any ideas ?

Thanks.
0 Kudos
Message 1 of 2
(2,857 Views)
If you over ride the "CWnd::PreTranslateMessage" function you'll be able to trap keyboard messages.

ex:

BOOL CTestexecDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 13 || pMsg->wParam == VK_ESCAPE))
{
// Enter or escape key was pressed; return TRUE to stop default handling
return TRUE;
}

if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x30)
{
BringWindowToTop( );
return TRUE;
}

if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x31 && m_DisplayObject1 != NULL)
{
// Enter or escape key was pressed; return TRUE to stop default handling
m_DisplayObject1->SetWindowToTop( );

return TRUE;
}
if (pMsg->message == WM_KEYDOWN && pMsg->wPa
ram == 0x32 && m_DisplayObject2 != NULL)
{
// Enter or escape key was pressed; return TRUE to stop default handling
m_DisplayObject2->SetWindowToTop( );

return TRUE;
}
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 0x33 && m_DisplayObject2 != NULL)
{
// Enter or escape key was pressed; return TRUE to stop default handling
m_DisplayObject3->SetWindowToTop( );

return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}



Steve
0 Kudos
Message 2 of 2
(2,857 Views)