PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: mice - usb devices  (Read 287 times)

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 186
mice - usb devices
« on: September 12, 2018, 06:06:29 PM »

It is possible to have more than one (at least two) mouse devices connected to a windows10 (maybe so for xp, 7, 8 too) PC at the same time. Any one of which will control the cursor. Is it possible to distinguish between the two in freebasic? My intention is to modify a mouse into a different sort of input device, but I need to discern if it is the modified devices button presses and x/y movements that are taking place. Is there any usb handling within freebasic?

Thanks, any help appreciated.
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 79
Re: mice - usb devices
« Reply #1 on: September 12, 2018, 11:37:34 PM »

Yes you can,
Look at GetRawInputData() and GetRawInputDeviceInfo()...

Code: [Select]
'Extract from Josť's stuff...
GetRawInputData function uiCommand = RID_HEADER

UNION RAWINPUT_UNION DWORD
   mouse     AS RAWMOUSE      ' RAWMOUSE
   keyboard  AS RAWKEYBOARD   ' RAWKEYBOARD
   hid       AS RAWHID        ' RAWHID
END UNION

UNION RAWINPUT_DATA_UNION DWORD
   data   AS RAWINPUT_UNION
   RAWINPUT_UNION
END UNION

TYPE RAWINPUT DWORD
   header AS RAWINPUTHEADER
   RAWINPUT_DATA_UNION
END TYPE

GetRawInputDeviceInfo function
 hDevice A handle to the raw input device.
 uiCommand (RIDI_DEVICENAME RIDI_DEVICEINFO RIDI_PREPARSEDDATA)
Logged

Josť Roca

  • FireFly3 Registered User
  • Master Member
  • *
  • Posts: 3083
    • Jos
Re: mice - usb devices
« Reply #2 on: September 13, 2018, 12:02:54 AM »

The declares and types for FreeBasic are available in winuser.bi, eg.

Code: [Select]
union tagRAWINPUT_data
mouse as RAWMOUSE
keyboard as RAWKEYBOARD
hid as RAWHID
end union

type tagRAWINPUT
header as RAWINPUTHEADER
data as tagRAWINPUT_data
end type

type RAWINPUT as tagRAWINPUT
type PRAWINPUT as tagRAWINPUT ptr
type LPRAWINPUT as tagRAWINPUT ptr

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 79
Re: mice - usb devices
« Reply #3 on: September 13, 2018, 12:25:13 AM »

Thank Josť, I was lazy, the one I used where from another universe...

[Added] Not to forget GetRawInputDeviceList()

Some keyboard code from the other universe, may be expanded for mouse...
« Last Edit: September 13, 2018, 01:37:11 AM by Pierre Bellisle »
Logged

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 186
Re: mice - usb devices
« Reply #4 on: September 13, 2018, 12:59:28 PM »

Thanks for your suggestions, Jose and Pierre.  Unfortunately, I'm not familiar with 'Jose's stuff', and have not got very far in my attempts so far. (at the moment I'm trying to use Paul's winfbe and graphical editor, and I've had to search for winuser.bi (which requires other binary files which I'll have to locate)). I'm guessing that Jose has more** or less put wrappers around the windows api's to enable easier use with Freebasic. Is there any chance, pretty please, that you could write for me, a complete program to, say, read a right button click from a specific mouse. Maybe a big ask, but if you've had a good day..., who knows. Hopefully, then I could discover how to read the other buttons, wheel, coordinates, etc.

At this stage, I'm not even sure how to distinguish between two identical mice . I suppose could plug one in first, or press a sequence of buttons.
I'm thinking it would be better to deal with a lower level of communication, e.g. i/o to the specific usb port, at least for the mouse I'm mechanically messing with. I've had a quick look at this, https://blogs.msdn.microsoft.com/usbcoreblog/2015/07/29/what-is-new-with-serial-in-windows-10/ which is most likely what I need to get to grips with, but not sure if it will be backwards compatible with w7, say. And it will most likely be difficult for me to get an understanding of it, I am not familiar with using windows api's, and what I've found on the web, and looks easy, https://freebasic.net/forum/viewtopic.php?f=7&t=13451 has been criticized in later posts. Are there any complete and better explained examples?

Best wishes,

Ray

** probably much more than that.
Logged

Josť Roca

  • FireFly3 Registered User
  • Master Member
  • *
  • Posts: 3083
    • Jos
Re: mice - usb devices
« Reply #5 on: September 13, 2018, 01:09:28 PM »

Winuser.bi in no my stuff. It is an include file that comes with the Free Basic compiler.

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 79
Re: mice - usb devices
« Reply #6 on: September 13, 2018, 01:47:04 PM »

Hi Ray,
Sadly on my side I don't think I will code around this subject in a near future...
Logged

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 186
Re: mice - usb devices
« Reply #7 on: September 13, 2018, 07:50:45 PM »

Anyway, thanks for your help, Pierre. I think I'm disappearing down a rabbit hole.  :( I thought I'd found a useful example (in html and javascript - but it needs visual studio, the code given will not run otherwise, at least, not for me.
Logged

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 186
Re: mice - usb devices
« Reply #8 on: September 16, 2018, 12:08:15 PM »

I'm coming to the conclusion that if I want to mess with the mouse, then a serial(RS232) device would be considerably easier for me, having in the past built serial hardware, etc. I have a usb to serial interface/connector lead, and when connected via usb, com ports are assigned, and the stop bits and so on can be set up in windows device manager, or hopefully within fb. It only allows xon/xoff protocol however, but that's OK. The optical usb mouse came with a ps2 connector adapter, and I have ps2 to serial adapters from way back, but I would have to power the mouse separately, because ps2 and usb has power through the connector. Now to rummage through, see if I can find any info on an old serial mouse (genius easymouse 2). Most likely, if I follow this through, eventually I'll be making a device based on a microchip device.
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 79
Re: mice - usb devices
« Reply #9 on: September 21, 2018, 08:20:44 AM »

If you are not comfortable with APIs then the GetRawInput*() families, and probably the SetupDI(), will be hard to manage.

Could a JoyStick be used?

Also, have a look at the freeware EitherMouse, use the zip for a no install standalone.

Logged

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 186
Re: mice - usb devices
« Reply #10 on: September 21, 2018, 03:08:36 PM »

Thanks Pierre, I'll download the eithermouse sw, see if it can be made to do what I want. The more I think about what I want to do, the more complicated it becomes. I have to somehow get it to interact with some existing Pascal software, for which I may not be able to get the source code. But as I know the author, I may be able to do some horse trading, possibly get him to do the alterations, if needed. fwiw, I found an old serial mouse, but I can't get it to work on my current desktop serial port. I think it used pin1 as a power source, but maybe another, dtr/whatever, to power the mouse chip. I can ring it through to try it out, and if necessary for proof of concept testing, power it externally.
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 79
Re: mice - usb devices
« Reply #11 on: September 22, 2018, 12:04:51 AM »

I'm not sure about the serial port you have, maybe it could be that
mice could "steal" +12vdc and -12vdc from original db9/db25 serial port.
USB adapter give only +5vdc, which might be too low

Also I noted on a project I had that when using a USB adapter instead of a genuine serial port 
I had to reverse the logic state of all signal.
Aka in my soft, treat positive RTS signal as negative, and so on for all pins.
Logged

raymw

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 186
Re: mice - usb devices
« Reply #12 on: September 22, 2018, 09:12:27 PM »

eithermouse  software is written in a scripting language - auto hot key- which until now I've not heard of, but the author includes the source, and encourages? folk to edit it. (another turn off the rabbit hole  for me ;)

Still, if it was easy, everyone would be doing it.
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 79
Re: mice - usb devices
« Reply #13 on: Today at 12:30:44 AM »

From the code, I see that EitherMouse use RawInput functions.

From program I had, Id did a quick test code under PowerBASIC using Josť's API.
I use some SetupDi functions to get connected mice info.
This is done via GetDeviceInfo("Mouse") function.

Compare HardId to MID$(DeviceName, 5, LEN(HardId)) (Convert # to _) to get the corresponding RawDevice if needed.

Then I call some RawInput functions to get mouse's stuff.
I'm sure you'll get the idea.
Code work mainly on mouse click.

I do not have time for now to translate to FB, plus, a lot of cleanup is needed but maybe in a week or so, maybe...

Code: [Select]
#COMPILE EXE
#DIM ALL
#REGISTER NONE
#INCLUDE "Win32Api.Inc"
#INCLUDE "WinUser.inc"
#INCLUDE "SetupAPI.inc"

%MAX_CLASS_NAME_LEN = 128

GLOBAL hDlg  AS DWORD
GLOBAL hEdit AS DWORD

$AppNmae      = "Mice"
%Edit         = 101
%ButtonAdd    = 201
%ButtonDel    = 202
%StaticCurPos = 301
$Line         = STRING$(75, 45)
'______________________________________________________________________________

SUB TextDel(BYVAL hEdit AS DWORD)

 'Erase all, Microsoft recommended way
  SendMessage(hEdit, %WM_SETTEXT, 0, BYVAL 0)

END SUB
'_____________________________________________________________________________

SUB TextAdd(BYVAL hEdit AS DWORD, BYVAL sText AS STRING)

 'Move the caret to the end of text.
 SendMessage(hEdit, %EM_SETSEL, -1, -1)

 sText = sText & $CRLF 'Add a CRLF if needed

 'Insert the string at caret position.
 SendMessage(hEdit, %EM_REPLACESEL, %TRUE, BYVAL STRPTR(sText))

END SUB
'_____________________________________________________________________________

FUNCTION MouseStateGet(usFlags AS WORD) AS STRING
 LOCAL sState AS STRING

 'usFlags Type: USHORT The mouse state. This member can be any reasonable combination of the following.
 IF (usFlags AND %MOUSE_MOVE_ABSOLUTE)      THEN
   sState &= "MOUSE_MOVE_ABSOLUTE, "      '1  Mouse movement data is based on absolute position.
 ELSE
   sState  = "MOUSE_MOVE_RELATIVE, "      '0    Mouse movement data is relative to the last mouse position.
 END IF
 IF (usFlags AND %MOUSE_VIRTUAL_DESKTOP)    THEN sState &= "MOUSE_VIRTUAL_DESKTOP, "    '0x02 Mouse coordinates are mapped to the virtual desktop (for a multiple monitor system).
 IF (usFlags AND %MOUSE_ATTRIBUTES_CHANGED) THEN sState &= "MOUSE_ATTRIBUTES_CHANGED, " '0x04 Mouse attributes changed; application needs to query the mouse attributes.
 FUNCTION = LEFT$(sState, -2) & " (0x" & HEX$(usFlags, 4) & ")"

END FUNCTION
'______________________________________________________________________________

FUNCTION MouseTransitionStateGet(usButtonFlags AS WORD) AS STRING
 LOCAL sState AS STRING

 'usButtonFlags The transition state of the mouse buttons. This member can be one or more of the following values.
 'The transition state of the mouse buttons. This member can be one or more of the following values.
 IF (usButtonFlags AND %RI_MOUSE_LEFT_BUTTON_DOWN)   THEN sState  = "RI_MOUSE_LEFT_BUTTON_DOWN, "   '0x0001 Left button changed to down.
 IF (usButtonFlags AND %RI_MOUSE_LEFT_BUTTON_UP)     THEN sState &= "RI_MOUSE_LEFT_BUTTON_UP, "     '0x0002 Left button changed to up.
 IF (usButtonFlags AND %RI_MOUSE_MIDDLE_BUTTON_DOWN) THEN sState &= "RI_MOUSE_MIDDLE_BUTTON_DOWN, " '0x0010 Middle button changed to down.
 IF (usButtonFlags AND %RI_MOUSE_MIDDLE_BUTTON_UP)   THEN sState &= "RI_MOUSE_MIDDLE_BUTTON_UP, "   '0x0020 Middle button changed to up.
 IF (usButtonFlags AND %RI_MOUSE_RIGHT_BUTTON_DOWN)  THEN sState &= "RI_MOUSE_RIGHT_BUTTON_DOWN, "  '0x0004 Right button changed to down.
 IF (usButtonFlags AND %RI_MOUSE_RIGHT_BUTTON_UP)    THEN sState &= "RI_MOUSE_RIGHT_BUTTON_UP, "    '0x0008 Right button changed to up.
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_1_DOWN)      THEN sState &= "RI_MOUSE_BUTTON_1_DOWN, "      '0x0001 RI_MOUSE_LEFT_BUTTON_DOWN
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_1_UP)        THEN sState &= "RI_MOUSE_BUTTON_1_UP, "        '0x0002 RI_MOUSE_LEFT_BUTTON_UP
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_2_DOWN)      THEN sState &= "RI_MOUSE_BUTTON_2_DOWN, "      '0x0004 RI_MOUSE_RIGHT_BUTTON_DOWN
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_2_UP)        THEN sState &= "RI_MOUSE_BUTTON_2_UP, "        '0x0008 RI_MOUSE_RIGHT_BUTTON_UP
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_3_DOWN)      THEN sState &= "RI_MOUSE_BUTTON_3_DOWN, "      '0x0010 RI_MOUSE_MIDDLE_BUTTON_DOWN
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_3_UP)        THEN sState &= "RI_MOUSE_BUTTON_3_UP, "        '0x0020 RI_MOUSE_MIDDLE_BUTTON_UP
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_4_DOWN)      THEN sState &= "RI_MOUSE_BUTTON_4_DOWN, "      '0x0040 XBUTTON1 changed to down.
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_4_UP)        THEN sState &= "RI_MOUSE_BUTTON_4_UP, "        '0x0080 XBUTTON1 changed to up.
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_5_DOWN)      THEN sState &= "RI_MOUSE_BUTTON_5_DOWN, "      '0x100  XBUTTON2 changed to down.
 IF (usButtonFlags AND %RI_MOUSE_BUTTON_5_UP)        THEN sState &= "RI_MOUSE_BUTTON_5_UP, "        '0x0200 XBUTTON2 changed to up.
 IF (usButtonFlags AND %RI_MOUSE_WHEEL)              THEN sState &= "RI_MOUSE_WHEEL, "              '0x0400 Raw input comes from a mouse wheel. The wheel delta is stored in usButtonData.
 FUNCTION = LEFT$(sState, -2) & " (0x" & HEX$(usButtonFlags, 4) & ")"

END FUNCTION
'______________________________________________________________________________

FUNCTION WinErrMsg2(BYVAL ErrNum AS DWORD)AS STRING
 LOCAL hLib      AS DWORD
 LOCAL errorFlag AS DWORD
 LOCAL os        AS OSVERSIONINFO
 LOCAL zError    AS ASCIIZ * 1024

 'Load error message module if available & necessary
 SELECT CASE AS LONG ErrNum

   CASE 2100 TO 2999 'NT, Network, thank Greg Turgeon
   'CASE %NETWORK_ERROR_FIRST TO %NETWORK_ERROR_LAST
     os.dwOSVersionInfoSize = SIZEOF(os)
     GetVersionEx os
     IF os.dwPlatformId = %VER_PLATFORM_WIN32_NT THEN _
       hLib = LoadLibraryEx("NETMSG.DLL", BYVAL 0, %LOAD_LIBRARY_AS_DATAFILE)

   CASE 12000 TO 12171 'Internet
   'CASE %INTERNET_ERROR_FIRST TO %NTERNET_ERROR_LAST
     hLib = LoadLibraryEx("WININET.DLL", BYVAL 0, %LOAD_LIBRARY_AS_DATAFILE)

 END SELECT

 errorFlag = %FORMAT_MESSAGE_FROM_SYSTEM OR %FORMAT_MESSAGE_IGNORE_INSERTS OR _
             %FORMAT_MESSAGE_MAX_WIDTH_MASK
 IF hLib THEN errorFlag = errorFlag OR %FORMAT_MESSAGE_FROM_HMODULE

 IF FormatMessage(errorFlag, BYVAL hLib, ErrNum, MakeLangID(%LANG_NEUTRAL, %SUBLANG_DEFAULT), _
                  zError, SIZEOF(zError), BYVAL 0) THEN
   FUNCTION = "Error" & STR$(ErrNum) & ":" & $SPC & zError
 ELSE
   'IF Unknown THEN
     FUNCTION = "Error" & STR$(ErrNum) & ", unknown."
   'END IF
 END IF
 IF hLib THEN FreeLibrary hLib

END FUNCTION
'______________________________________________________________________________

FUNCTION SetupDiGetDeviceRegistryPropertyCall(BYVAL hDeviceInfoSet AS DWORD, DeviceInfoData AS SP_DEVINFO_DATA, BYVAL PropertyVal AS DWORD, BYVAL sDef AS STRING) AS STRING
 LOCAL zPropertyBuffer     AS ASCIIZ * 2048
 LOCAL pz                  AS ASCIIZ POINTER
 LOCAL sBuf                AS STRING
 LOCAL RequiredSize        AS DWORD
 LOCAL PropertyRegDataType AS DWORD
 LOCAL index               AS LONG
 LOCAL LastError           AS LONG

 DeviceInfoData.cbSize       = SIZEOF(SP_DEVINFO_DATA)
 IF SetupDiGetDeviceRegistryProperty(hDeviceInfoSet, _       'Return True if success
                                     DeviceInfoData, _       'SP_DEVINFO_DATA var
                                     PropertyVal, _          'Aka SPDRP_BUSNUMBER, %SPDRP_FRIENDLYNAME
                                     PropertyRegDataType, _  'Reg type of data received
                                     zPropertyBuffer, _      'Data received
                                     SIZEOF(zPropertyBuffer), _
                                     RequiredSize) THEN      'Required size for the PropertyBuffer buffer

   'REG_NONE                        =  0   No value type
   'REG_SZ                          =  1   Unicode nul terminated string
   'REG_EXPAND_SZ                   =  2   Unicode nul terminated string
   'REG_BINARY                      =  3   Free form binary
   'REG_DWORD                       =  4   32-bit number
   'REG_DWORD_LITTLE_ENDIAN         =  4   32-bit number (same as MACRO REG_DWORD)
   'REG_DWORD_BIG_ENDIAN            =  5   32-bit number
   'REG_LINK                        =  6   Symbolic Link (unicode)
   'REG_MULTI_SZ                    =  7   Multiple Unicode strings
   'REG_RESOURCE_LIST               =  8   Resource list in the resource map
   'REG_FULL_RESOURCE_DESCRIPTOR    =  9   Resource list in the hardware description
   'REG_RESOURCE_REQUIREMENTS_LIST  = 10
   'REG_QWORD                       = 11   64-bit number
   'REG_QWORD_LITTLE_ENDIAN         = 11   64-bit number (same as MACRO REG_QWORD)

   SELECT CASE PropertyRegDataType

     CASE %REG_SZ '1
       'Nothing to do            'pz = VARPTR(zPropertyBuffer) 'zPropertyBuffer = @pz

     CASE %REG_DWORD '4
       zPropertyBuffer = "0x" & HEX$(CVDWD(zPropertyBuffer), 8) 'Convert from DWORD

     CASE %REG_BINARY '3
       FOR index = 1 TO RequiredSize
         sBuf = sBuf & HEX$(ASC(zPropertyBuffer, index), 2) & $SPC
       NEXT : zPropertyBuffer = sBuf

     CASE %REG_MULTI_SZ '7
       pz = VARPTR(zPropertyBuffer) : sBuf = ""
       WHILE LEN(@pz)
         sBuf = sBuf & "[" & @pz & "]" : pz = pz + LEN(@pz)
       WEND : zPropertyBuffer = sBuf

     CASE ELSE
       zPropertyBuffer = "0x" & HEX$(CVDWD(zPropertyBuffer)) 'Convert from DWORD

   END SELECT

   zPropertyBuffer = sDef & $TAB & zPropertyBuffer '& "   (" & REMed ValueDataTypeGet(PropertyRegDataType) & ")"
 ELSE
   LastError = GetLastError()
   zPropertyBuffer = WinErrMsg2(LastError)
   'Returns ERROR_INVALID_DATA if the property does not exist or if the property data is not valid. 0x8007000D
   IF LastError = %ERROR_INVALID_DATA THEN zPropertyBuffer = sDef & $TAB & "[none] Property might not exist : " & zPropertyBuffer
 END IF

 FUNCTION = zPropertyBuffer

END FUNCTION
'______________________________________________________________________________
« Last Edit: Today at 12:33:38 AM by Pierre Bellisle »
Logged

Pierre Bellisle

  • FireFly3 User
  • Junior Member
  • *
  • Posts: 79
Re: mice - usb devices
« Reply #14 on: Today at 12:31:22 AM »

Part two
Code: [Select]
FUNCTION GetDeviceInfo(Device AS STRING) AS LONG
 LOCAL zClassName     AS ASCIIZ * %MAX_CLASS_NAME_LEN '=128
 LOCAL DeviceInfoData AS SP_DEVINFO_DATA
 LOCAL hDeviceInfoSet AS DWORD
 LOCAL RequiredSize   AS DWORD
 LOCAL DevCount       AS LONG
 LOCAL Retval         AS LONG

 zClassName = Device
 DevCount   = 0

 'The SetupDiClassGuidsFromName function retrieves the GUID(s) associated with the specified class name.
 'This list is built based on the classes currently installed on the system.
 Retval = SetupDiClassGuidsFromName(zClassName, BYVAL 0, BYVAL 0, RequiredSize) 'Ask for array size
 TextAdd(hEdit, "SetupDi devices" & $TAB) 'DeviceCount

 REDIM GuidArray(1 TO RequiredSize) AS GUIDAPI
 Retval = SetupDiClassGuidsFromName(zClassName, GuidArray(1), _ 'Ask for GUID associated with the class name
                                    SIZEOF(GUIDAPI) * RequiredSize, RequiredSize)

 'SetupDiGetClassDevs retrieves a device information set that contains all devices of a specified class.
 'Get info by ClassGUID, like GUID$("{4D36E978E325-11CE-BFC1-08002BE10318})" for "Ports"
 hDeviceInfoSet = SetupDiGetClassDevs(GuidArray(1), BYVAL %NULL, BYVAL %NULL, %DIGCF_PRESENT)
 IF hDeviceInfoSet <> %INVALID_HANDLE_VALUE THEN
   DeviceInfoData.cbSize = SIZEOF(DeviceInfoData)
   DO 'Loop to get all devices of a class
     'Get a device based on DevCount, exit if no more
     IF SetupDiEnumDeviceInfo(hDeviceInfoSet, DevCount, DeviceInfoData) THEN 'Return True if success
       TextAdd(hEdit, $Line)
       TextAdd(hEdit, "Device no.: " & $TAB & FORMAT$(DevCount))
       TextAdd(hEdit, "ClassName: " & zClassName)
       TextAdd(hEdit, "GUID: " & GUIDTXT$(GuidArray(1)))
       TextAdd(hEdit, SetupDiGetDeviceRegistryPropertyCall(hDeviceInfoSet, DeviceInfoData, %SPDRP_FRIENDLYNAME, "FriendlyName: "))
       TextAdd(hEdit, SetupDiGetDeviceRegistryPropertyCall(hDeviceInfoSet, DeviceInfoData, %SPDRP_DEVICEDESC, "Desc: "))
       TextAdd(hEdit, SetupDiGetDeviceRegistryPropertyCall(hDeviceInfoSet, DeviceInfoData, %SPDRP_DRIVER, "Driver: "))
       TextAdd(hEdit, SetupDiGetDeviceRegistryPropertyCall(hDeviceInfoSet, DeviceInfoData, %SPDRP_HARDWAREID, "HardId: "))
       TextAdd(hEdit, SetupDiGetDeviceRegistryPropertyCall(hDeviceInfoSet, DeviceInfoData, %SPDRP_ENUMERATOR_NAME, "Enum: "))
       TextAdd(hEdit, SetupDiGetDeviceRegistryPropertyCall(hDeviceInfoSet, DeviceInfoData, %SPDRP_MFG, "MFG: "))
       TextAdd(hEdit, SetupDiGetDeviceRegistryPropertyCall(hDeviceInfoSet, DeviceInfoData, %SPDRP_SERVICE, "Servcice: "))
       TextAdd(hEdit, SetupDiGetDeviceRegistryPropertyCall(hDeviceInfoSet, DeviceInfoData, %SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, "PhyObj: "))
     ELSE
       EXIT DO
     END IF
     INCR DevCount
   LOOP
   SetupDiDestroyDeviceInfoList(hDeviceInfoSet) ': hDeviceInfoSet = 0
 END IF

 TextAdd(hEdit, $Line)

END FUNCTION
'______________________________________________________________________________

CALLBACK FUNCTION DlgProc
 LOCAL  CurPos            AS POINTAPI
 LOCAL  index             AS LONG
 LOCAL  RidDeviceInfo     AS RID_DEVICE_INFO
 LOCAL  RawInputDevCount  AS LONG
 LOCAL  MouseCount        AS LONG
 LOCAL  DataSize          AS LONG
 LOCAL  ByteCount         AS LONG
 LOCAL  RidDeviceInfoSize AS DWORD 'RID_DEVICE_INFO

 SELECT CASE CBMSG

   CASE %WM_INITDIALOG
     'Edit -------------------------------------------------------------------
     hEdit = GetDlgItem(CBHNDL, %Edit)
     SendMessage(hEdit, %EM_LIMITTEXT, 0, 0)
     PostMessage(hEdit, %EM_SETSEL, -1, -1)
     PostMessage(CBHNDL, %WM_APP, 0, 0)

   CASE %WM_APP

     'SetupDi ----------------------------------------------------------------
     GetDeviceInfo("Mouse")

     'Raw --------------------------------------------------------------------
     GetRawInputDeviceList(BYVAL %NULL, RawInputDevCount, SIZEOF(RAWINPUTDEVICELIST))         'Get hid count
     DIM RawInputDevList(0 TO RawInputDevCount - 1) AS RAWINPUTDEVICELIST                     'Prepare hid array
     GetRawInputDeviceList(RawInputDevList(0), RawInputDevCount, SIZEOF(RAWINPUTDEVICELIST))  'Get array
     TextAdd(hEdit, "All RawInputDevCount" & $TAB & STR$(RawInputDevCount))
     TextAdd(hEdit, $Line)
     DIM RawInputDev(0 TO RawInputDevCount) AS RAWINPUTDEVICE                                      'Prepare hid register array
     TextAdd(hEdit, "RawInputDevice Mouse" & $TAB)
     TextAdd(hEdit, $Line)
     RidDeviceInfoSize = SIZEOF(RID_DEVICE_INFO)
     FOR index = 0 TO RawInputDevCount - 1                                                  'Loop
       GetRawInputDeviceInfo(RawInputDevList(index).hDevice, %RIDI_DEVICEINFO, RidDeviceInfo, SIZEOF(RID_DEVICE_INFO)) 'Get hid info
       SELECT CASE RidDeviceInfo.dwtype                                                  'Poll hid type
         CASE %RIM_TYPEMOUSE                                                             'Mouse
           LOCAL zDeviceName AS ASCIIZ * 128
           GetRawInputDeviceInfo(RawInputDevList(index).hDevice, %RIDI_DEVICENAME, BYVAL VARPTR(zDeviceName), SIZEOF(zDeviceName))
           GetRawInputDeviceInfo(RawInputDevList(index).hDevice, %RIDI_DEVICEINFO, RidDeviceInfo, RidDeviceInfoSize)
           TextAdd(hEdit, "DeviceName: " & $TAB & zDeviceName)
           TextAdd(hEdit, "Type: "       & $TAB & "Mouse")
           TextAdd(hEdit, "index: "      & $TAB & STR$(MouseCount))
           TextAdd(hEdit, "hDevice: "    & $TAB & HEX$(RawInputDevList(index).hDevice))
           TextAdd(hEdit, "Moude id:"    & $TAB & STR$(RidDeviceInfo.mouse.dwId))
           TextAdd(hEdit, "Button count:" & $TAB & STR$(RidDeviceInfo.mouse.dwNumberOfButtons))
           TextAdd(hEdit, "Sample rate data points per second:" & $TAB & STR$(RidDeviceInfo.mouse.dwSampleRate))
           TextAdd(hEdit, "Horizontal wheel scrolling:"         & $TAB & STR$(RidDeviceInfo.mouse.fHasHorizontalWheel))

           DataSize = GetRawInputDeviceInfo(RawInputDevList(index).hDevice, %RIDI_PREPARSEDDATA, BYVAL %NULL, VARPTR(DataSize))
           TextAdd(hEdit, "Preparsed data byte count  " & $TAB & STR$(DataSize))

           '    1 - generic desktop controls // we use this
           '    2 - simulation controls
           '    3 - vr
           '    4 - sport
           '    5 - game
           '    6 - generic device
           '    7 - keyboard
           '    8 - LEDs
           '    9 - button
           RawInputDev(MouseCount).usUsagePage = 1

           'usUsage values when usUsagePage is 1:
           '    0 - undefined
           '    1 - pointer
           '    2 - mouse
           '    3 - reserved
           '    4 - joystick
           '    5 - game pad
           '    6 - keyboard // we use this
           '    7 - keypad
           '    8 - multi-axis controller
           '    9 - Tablet PC controls
           RawInputDev(MouseCount).usUsage     = 2

           RawInputDev(MouseCount).dwFlags     = %RIDEV_EXINPUTSINK 'Always capture nofreezw
           'RawInputDev(MouseCount).dwFlags    = %RIDEV_NOLEGACY 'Add mouse and ignores legacy mouse messages freeze
           'RawInputDev(MouseCount).dwFlags    = %RIDEV_CAPTUREMOUSE 'nofreeze
           RawInputDev(MouseCount).hwndTarget  = hDlg

           TextAdd(hEdit, $Line)
           INCR MouseCount

         CASE %RIM_TYPEKEYBOARD 'Keyboard, the presenter shows up as a keyboard too

         CASE %RIM_TYPEHID 'Other devices                                                               'Other raw input device, game controllers, joysticks, etc.

       END SELECT
     NEXT

     TextAdd(hEdit, $Line)
     RegisterRawInputDevices(RawInputDev(0), MouseCount, SIZEOF(RAWINPUTDEVICE)) 'Register hids

   CASE %WM_INPUT 'Sent to the window that is getting raw input. By default, no application receives raw input.
                  'The first step is therefore to register the input devices that will be providing the
                  'desired raw data, and associate them with the window that will be handling this data.
                  'wParam = The input code. This parameter can be one of the following values.
                  '         RIM_INPUT     0 Input occurred while the application was in the foreground.
                  '                       The application must call DefWindowProc so the system can perform cleanup.
                  '         RIM_INPUTSINK 1 Input occurred while the application was not in the foreground.
                  '                       The application must call DefWindowProc so the system can perform the cleanup.
                  'lParam   A handle to the RAWINPUT for GetRawInputData that contains the raw input from the device.

     STATIC zRawInput  AS STRING * 4096 'Faster than building a ~40 bytes string every time
     LOCAL  pRawInput  AS RAWINPUT POINTER
     LOCAL  ByteCountF AS LONG
     pRawInput  = VARPTR(zRawInput)
     ByteCount  = LEN(zRawInput)
     ByteCountF = GetRawInputData(CBLPARAM, %RID_INPUT, BYVAL pRawInput, ByteCount, SIZEOF(RAWINPUTHEADER))'Get hid input
     IF @pRawInput.data.mouse.usButtonFlags THEN
       TextAdd(hEdit, "RawInput.Header.hDevice = "                & HEX$(@pRawInput.header.hDevice, 8))
       TextAdd(hEdit, "RawInput.Header.dwType = "                 & CHOOSE$(@pRawInput.header.dwType + 1, _  '0 for mouse, 1 key, 2 hid
                                                                            "RIM_TYPEMOUSE", "RIM_TYPEKEYBOARD", "RIM_TYPEHID")) '0 for mouse, 1 key, 2 hid
       TextAdd(hEdit, "RawInput.Header.wParam = "                 & HEX$(@pRawInput.header.wParam, 8)) 'The value passed in the wParam parameter of the WM_INPUT message.
       TextAdd(hEdit, "RawInput.data.mouse.usFlags = "            & MouseStateGet(@pRawInput.data.mouse.usFlags)) '
       TextAdd(hEdit, "RawInput.data.mouse.usButtonFlags = "      & MouseTransitionStateGet(@pRawInput.data.mouse.usButtonFlags)) '
       TextAdd(hEdit, "RawInput.data.mouse.usButtonData = "       & HEX$(@pRawInput.data.mouse.usButtonData, 4)) '
       TextAdd(hEdit, "RawInput.data.mouse.ulRawButtons = "       & FORMAT$(@pRawInput.data.mouse.ulRawButtons)) 'Reserved
       TextAdd(hEdit, "RawInput.data.mouse.lLastX = "             & FORMAT$(@pRawInput.data.mouse.lLastX)) 'The motion in the X direction. This is signed relative motion or absolute motion, depending on the value of usFlags.
       TextAdd(hEdit, "RawInput.data.mouse.lLastY = "             & FORMAT$(@pRawInput.data.mouse.lLastY)) 'The motion in the Y direction. This is signed relative motion or absolute motion, depending on the value of usFlags.
       TextAdd(hEdit, "RawInput.data.mouse.ulExtraInformation = " & HEX$(@pRawInput.data.mouse.ulExtraInformation)) '
       GetCursorPos(CurPos)
       TextAdd(hEdit, "Cursor: " & FORMAT$(CurPos.x) & " x "      & FORMAT$(CurPos.x))
       TextAdd(hEdit, $Line)
     END IF

     DefWindowProc(hDlg, CBMSG, CBWPARAM, CBLPARAM)
     FUNCTION = 0 : EXIT FUNCTION

   CASE %WM_INPUT_DEVICE_CHANGE 'RIDEV_DEVNOTIFY Sent to the window that registered to receive raw input.
     'wParam This parameter can be one of the following values.
     '  GIDC_ARRIVAL 1 A new device has been added to the system.
     '  GIDC_REMOVAL 2 A device has been removed from the system.
     'lParam The handle to the raw input device. Call GetRawInputDeviceInfo to get more information regarding the device.

   CASE %WM_COMMAND
     SELECT CASE LOWRD(CBWPARAM)
       CASE %ButtonAdd
         IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
         END IF

       CASE %ButtonDel
         IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
           TextDel(hEdit)
         END IF

       CASE %IDCANCEL, %IDOK
         IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
           DIALOG END CBHNDL, 0
         END IF
     END SELECT

   CASE %WM_SETCURSOR
     'hwnd = (HWND) wParam;       // handle of window with cursor
     'nHittest = LOWORD(lParam);  // hit-test code
     'wMouseMsg = HIWORD(lParam); // mouse-message identifier
      GetCursorPos(CurPos)
      CONTROL SET TEXT hDlg, %StaticCurPos, FORMAT$(CurPos.x) & " x " & FORMAT$(Curpos.y)

   CASE %WM_SIZE 'Dialog size have changed
     'CBWPARAM = Resizing requested: SIZE_MAXHIDE SIZE_MAXIMIZED SIZE_MAXSHOW SIZE_MINIMIZED SIZE_RESTORED
     'LO(WORD, CBLPARAM) is client area width  in pixels.
     'HI(WORD, CBLPARAM) is client area height in pixels.
     LOCAL ClientSizeX AS LONG
     LOCAL ClientSizeY AS LONG
     IF CBWPARAM <> %SIZE_MINIMIZED THEN
       ClientSizeX = LO(WORD, CBLPARAM)
       ClientSizeY = HI(WORD, CBLPARAM)
       MoveWindow(hEdit, 3, 3, ClientSizeX - 8, ClientSizeY - 40 - 00, %TRUE)
       MoveWindow(GetDlgItem(hDlg, %ButtonAdd), 10, ClientSizeY - 30, 180, 25, %TRUE)
       MoveWindow(GetDlgItem(hDlg, %ButtonDel), 200, ClientSizeY - 30, 80, 25, %TRUE)
       MoveWindow(GetDlgItem(hDlg, %StaticCurPos), 320, ClientSizeY - 25, 80, 25, %TRUE)
     END IF

 END SELECT
END FUNCTION
'______________________________________________________________________________

FUNCTION PBMAIN
 LOCAL hIcon  AS DWORD

 DIALOG NEW %HWND_DESKTOP, $AppNmae, , , 450, 600, _
 %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_SYSMENU OR %WS_THICKFRAME, 0 TO hDlg
 hIcon = ExtractIcon(GETMODULEHANDLE(""), "Shell32.dll", 294)
 SetClassLong(hDlg, %GCL_HICON,hIcon)

 CONTROL ADD TEXTBOX, hDlg, %Edit, "", 2, 2, 196, 96, %WS_CHILD OR %WS_VISIBLE OR _
 %WS_TABSTOP OR %WS_HSCROLL OR %WS_VSCROLL OR %ES_LEFT OR %ES_MULTILINE OR _
 %ES_NOHIDESEL OR %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL OR %ES_WANTRETURN, _
 %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR

 CONTROL ADD BUTTON, hDlg, %ButtonAdd, "&Add string at the end and scrool", 10, 86, 130, 15

 CONTROL ADD BUTTON, hDlg, %ButtonDel, "&Delete text", 150, 86, 55, 15

 CONTROL ADD LABEL, hDlg, %StaticCurPos, "CurPos", 230, 86, 55, 15

 DIALOG SHOW MODAL hDlg CALL DlgProc
 DestroyIcon(hIcon)

END FUNCTION
'______________________________________________________________________________
'
Logged
Pages: [1] 2