我用timer.tick 通過
GetAsyncKeyState(VK_LBUTTON)
否則 https://msdn.microsoft.com/en-us/library/windows/desktop/ms646290(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms646298(v=vs.85).aspx
How to Check if User input is from Barcode Scanner or Keyboard?
是比較容易與原始輸入API來完成創建numpadkeys和循環數組。
看看「從鍵盤上區分條碼掃描儀的WinForms中的」
我有一個程序,讀取3臺不同的USB掃描儀和重定向輸入到3個不同的「通道」進行處理。代碼有點廣泛,所以我不在這裏發佈。如果你願意,我可以粘貼它的一些塊或者通過電子郵件發送給你項目。
爲線索是進口:
#region Raw Input API
[DllImport("User32.dll")]
extern static uint GetRawInputDeviceList(IntPtr pRawInputDeviceList, ref uint uiNumDevices, uint cbSize);
[DllImport("User32.dll")]
extern static uint GetRawInputDeviceInfo(IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
[DllImport("User32.dll")]
extern static bool RegisterRawInputDevices(RAWINPUTDEVICE[ ] pRawInputDevice, uint uiNumDevices, uint cbSize);
[DllImport("User32.dll")]
extern static uint GetRawInputData(IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader);
#endregion
後您添加的InputDevice到你的項目,你可以聽由事件:
//創建一個新的InputDevice對象和註冊的InputDevice keyPressed事件處理程序。
input_dev = new InputDevice(Handle);
input_dev.KeyPressed += new InputDevice.DeviceEventHandler(m_KeyPressed);
The event handler m_KeyPressed lets you to distinguish your devices through e.Keyboard.SubClass
private void m_KeyPressed(object sender, InputDevice.KeyControlEventArgs e)
{
// e.Keyboard.SubClass tells you where from the event came.
// e.Keyboard.key gives you the input data.
}
希望能有所幫助。
是可能的附加信息附加到的窗口消息(見[SetMessageExtraInfo](HTTPS:/ /msdn.microsoft.com/en-us/library/windows/desktop/ms644954.aspx))。您是否檢查了條形碼掃描儀的文檔以查看是否可以提供其他信息? – IInspectable