i working in access 2013 , try getrawinputdevicelist, getrawinputdeviceinfo, registerrawinputdevices , getrawinputdata equivalents vba no success. have searched in vain procedure, function or module list of connected hid devices computer pick out barcode scanner. beginning of third week on knees begging assistance. of have module you're willing share, link website dealt with? appreciated.
using getrawinputdevicelist api vba pretty tricky because of prawinputdevicelist parameter. unless you're willing jump through ton of hoops manage own memory , manually handle resulting array of rawinputdevicelist in raw memory, you'll better off coming @ direction.
most barcode scanners i've dealt present windows keyboard. 1 possible solution use wmi query enumerate attached win32_keyboard devices:
private sub showkeyboardinfo() dim wmiserver object dim resultset object dim keyboard object dim query string query = "select * win32_keyboard" set wmiserver = getobject("winmgmts:root/cimv2") set resultset = wmiserver.execquery(query) each keyboard in resultset debug.print keyboard.name & vbtab & _ keyboard.description & vbtab & _ keyboard.deviceid & vbtab & _ keyboard.status next keyboard end sub
note: if doesn't turn there, can enumerate of usb devices querying cim_usbdevice: query = "select * win32_keyboard"
edit: per comments, above code won't return handle needed register receive raw input events. should started though - registerrawinputdevices , getrawinputdata aspects beyond scope of go in answer. take hack @ it, , if run problems post code in question.
declarations:
private type rawinputdevicelist hdevice long dwtype long end type private type ridkeyboardinfo cbsize long dwtype long dwkeyboardmode long dwnumberoffunctionkeys long dwnumberofindicators long dwnumberofkeystotal long end type private enum devicetype typemouse = 0 typekeyboard = 1 typehid = 2 end enum private enum devicecommand devicename = &h20000007 deviceinfo = &h2000000b preparsedata = &h20000005 end enum private declare function getrawinputdevicelist lib "user32" ( _ byval prawinputdevicelist long, _ byref puinumdevices long, _ byval cbsize long) long private declare function getrawinputdeviceinfo lib "user32" alias "getrawinputdeviceinfow" ( _ byval hdevice long, _ byval uicommand long, _ byval pdata long, _ byref pcbsize long) long private declare function getlasterror lib "kernel32" () long
sample of retrieving device names getrawinputdeviceinfo:
private sub samplecode() dim devices() rawinputdevicelist devices = getrawinputdevices dim long = 0 ubound(devices) 'inspect type - looking keyboard. if devices(i).dwtype = typekeyboard dim buffer string dim size long 'first call null pointer returns string length in size. if getrawinputdeviceinfo(devices(i).hdevice, devicename, 0&, size) = -1 debug.print "getrawinputdeviceinfo error " & getlasterror() else 'size string buffer. buffer = string(size, chr$(0)) 'the second call copies name passed buffer. if getrawinputdeviceinfo(devices(i).hdevice, devicename, strptr(buffer), size) = -1 debug.print "getrawinputdeviceinfo error " & getlasterror() else debug.print buffer end if end if end if next end sub private function getrawinputdevices() rawinputdevicelist() dim devs long dim output() rawinputdevicelist 'first call null pointer returns number of devices in devs if getrawinputdevicelist(0&, devs, lenb(output(0))) = -1 debug.print "getrawinputdevicelist error " & getlasterror() else 'size output array. redim output(devs - 1) 'second call fills array. if getrawinputdevicelist(varptr(output(0)), devs, lenb(output(0))) = -1 debug.print "getrawinputdevicelist error " & getlasterror() else getrawinputdevices = output end if end if end function
sorry side scrolling.
Comments
Post a Comment