如何从指定的输入设备获取输入值
各位大佬好,我想做一个通过条码查询的后台程序,如何获取从条码枪输入的字符串呢,请各位大佬给指点一下,谢谢。 在网上找到以下链接,有兴趣的一起研究一下http://www.autoitscript.com/forum/topic/95105-hid-human-interface-device-communications-in-xp/?hl=barcode 只是处理字符串的可能不是很难,但是不知道条形码枪是怎么个工作原理,不敢乱说~ 本帖最后由 yuxw 于 2013-6-4 17:24 编辑
谢谢,根据2楼的链接,得到解决。思路就是获取扫描码的相关ID号,判断输入来源。Global $tRID_KD, $pRID_KD, $iRID_KD
Global $tRIH, $pRIH, $iRIH
Global $iNumDevices
Global $hGUI , $pData,$t
$on=1
$hGUI = GUICreate('Test', 100, 100)
GUIRegisterMsg($WM_INPUT, 'OnInput')
$tRID_KD = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_KD = DllStructGetPtr($tRID_KD)
$iRID_KD = DllStructGetSize($tRID_KD)
$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$pRIH = DllStructGetPtr($tRIH)
$iRIH = DllStructGetSize($tRIH)
$iNumDevices = 1
DllStructSetData($tRID_KD, 'usUsagePage', 0x01)
DllStructSetData($tRID_KD, 'usUsage', 0x06)
DllStructSetData($tRID_KD, 'dwFlags', BitOR($RIDEV_NOLEGACY, $RIDEV_INPUTSINK))
DllStructSetData($tRID_KD, 'hwndTarget', $hGUI)
_RegisterRawInputDevices($pRID_KD, $iNumDevices, $iRID_KD)
While 1
Sleep(10)
WEnd
Func OnInput($hwnd, $iMsg, $iwParam, $ilParam)
Local $tRI_KD, $pRI_KD, $iRI_KB
Local $tRIDI_HID, $pRIDI_HID, $iRIDI_HID
Local $hDevice
$tRI_KD = DllStructCreate($tagRAWINPUT_KEYBOARD)
$pRI_KD = DllStructGetPtr($tRI_KD)
$iRI_KB = DllStructGetSize($tRI_KD)
$tRIDI_HID = DllStructCreate($tagRIDDEVICEINFO_HID)
$pRIDI_HID = DllStructGetPtr($tRIDI_HID)
$iRIDI_HID = DllStructGetSize($tRIDI_HID)
;DllStructSetData($tRID_KD, 'dwFlags', BitOR($RIDEV_NOLEGACY, $RIDEV_INPUTSINK))
;672042073313Dll672042073313StructSetData($tRID_KD, 'dwFlags', BitOR($RIDEV_NOLEGACY, $RIDEV_INPUTSINK))
DllStructSetData($tRIDI_HID, 'cbSize', $iRIDI_HID)
_GetRawInputData($ilParam, $RID_INPUT, $pRI_KD, $iRI_KB, $iRIH)
If Not @error Then
$hDevice = DllStructGetData($tRI_KD, 'hDevice')
$vKey = DllStructGetData($tRI_KD, 'VKey');F3 = 114
EndIf
_GetRawInputDeviceInfo($hDevice, $RIDI_DEVICEINFO, $pRIDI_HID, $iRIDI_HID)
If Not @error Then
$hDevice2= DllStructGetData($tRI_KD, 'hDevice')
$dwVendorId= DllStructGetData($tRIDI_HID, 'dwVendorId')
$dwProductId = DllStructGetData($tRIDI_HID, 'dwProductId')
$dwType = DllStructGetData($tRI_KD, 'dwType')
EndIf
If $dwVendorId = 81 Then
If $on Then
$t=$t&key($vKey)
ConsoleWrite($t&@CR)
$on=0
Else
$on=1
EndIf
EndIf
$tRI_KD = 0
if $vKey=13Then
ConsoleWrite(121)
endif
endfunc不知道为什么每个数字会出现2次,如果为字符会出现3次
相关的UFO就从上面的链接下吧。 看不懂,继续研究
页:
[1]