RawInput Devices

Just starting out? Need help? Post your questions and find answers here.
IndiepathT
New User
New User
Posts: 2
Joined: Tue Feb 22, 2005 8:58 pm

RawInput Devices

Post by IndiepathT »

It is possible to access RawInputdevices in C/C++ via the User32.dll , this is necessary it you want more than one mouse in your application for example.

Does anybody know how I can access these functions from within Purebasic.

GetRawInputData_ is the main function I require.

Hope you can help.

Thanks.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: RawInput Devices

Post by traumatic »

Welcome to the forums.

Well, I don't know if I got your question right but I'll give it a shot anyway:
Basically, you can use any API function in PureBasic even if they are not defined,
ie API_Function_().

To do that, you could either access the appropriate DLL directly, like...

Code: Select all

OpenLibrary(0, "user32.dll")

*f = IsFunction(0, "GetRawInputData")

If *f
  If CallFunctionFast(*f, hRawInput.RAWINPUT, #RID_INPUT, #NULL, @pcbSize.l, SizeOf(RAWINPUTHEADER)) <> -1
    ;
    ; yadayadayada
    ;
  EndIf
EndIf

CloseLibrary(0)
...or alternatively use PB's DLL-Importer. That's a matter of taste and handling.

The next issue you'll encounter is that none of the structures or constants you need
are pre-defined in PureBasic but that shouldn't be much of a problem.

With a basic understanding of C (or good imagination ;)) you'll be able to convert
the required headers to PB in next to no time.

I had a quick peek at MSDN and found the following which may be useful to
give you an idea:

Code: Select all

;  see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/rawinput.asp

#RID_INPUT = $10000003

Structure RAWINPUTHEADER
  dwType.l
  dwSize.l
  hDevice.l
  wParam.l
EndStructure


Structure usButtonHELP
  usButtonFlags.w
  usButtonData.w
EndStructure


Structure RAWMOUSE
  usFlags.w
  StructureUnion
    ulButtons.l
    usButton.usButtonHELP
  EndStructureUnion

  ulRawButtons.l
  lLastX.l
  lLastY.l
  ulExtraInformation.l
EndStructure

Structure RAWKEYBOARD
  MakeCod.w
  Flags.w
  Reserved.w
  VKey.w
  Message.l
  ExtraInformation.l
EndStructure

Structure RAWHID
  dwSizeHid.l
  dwCount.l
  bRawData.b
EndStructure

Structure RAWDATA
  StructureUnion
    mouse.RAWMOUSE
    keyboard.RAWKEYBOARD
    hid.RAWHID
  EndStructureUnion
EndStructure


Structure RAWINPUT
    header.RAWINPUTHEADER
    Data.RAWDATA
EndStructure
I must admit, I never heard of these RawInput routines before and I should
already be sleeping for 2-3 hours now :P - so please double-check the structures
as they may well contain errors!

BTW: As far as I could see you have to register the device beforehand but
you may already know that. :)

Hope that helps.
Good programmers don't comment their code. It was hard to write, should be hard to read.
IndiepathT
New User
New User
Posts: 2
Joined: Tue Feb 22, 2005 8:58 pm

Post by IndiepathT »

Thanks for that, this will prove very useful.
vanleth
User
User
Posts: 79
Joined: Sat Jun 28, 2003 4:39 am
Location: Denmark - Valby

Post by vanleth »

Any got a working example of using the RawInput buffer with a mouse?

Been messing with it abit now, and so far without luck. Got to the point where I can recieve the WM_INPUT events in a windowcallback procedure and examine them with GetRawInputData. But I never get any success with the GetRawInputBuffer command.

a link to msdn about raw input:
http://msdn.microsoft.com/library/defau ... winput.asp

btw I think one of the structures in the above examples is abit wrong.

Code: Select all

Structure RAWMOUSE
	unitid.w ; <---- this needs added.
	usFlags.w
	StructureUnion
		ulButtons.l
		usButton.usButtonHELP
	EndStructureUnion	
	ulRawButtons.l
	lLastX.l
	lLastY.l
	ulExtraInformation.l
EndStructure
If needed I will post a example of my struggles laters, just abit tied up now.

Kind regards
Post Reply