Hi,

I have a USB device that Windows treats as a mouse. However, I would
like to use it to control another application instead of moving the
mouse pointer.

I have been able to get the raw data from the device using the raw input
API and WM_INPUT messages, so I can control the application, but
unfortunately the mouse pointer moves as well. Is there any way that I
can somehow prevent the default processing of the information? Do I need
to write some sort of driver to intercept the device before it gets
recognised as a mouse? I am hoping that there is a very simple obvious
solution that I've missed.

Thanks for any help,

Simon

Re: Raw Input from Mouse-like HID device by nospam

nospam
Tue Nov 09 13:35:15 CST 2004

You need an upper filter driver, see example in WINDDK\src\input\moufiltr.
We have also got one for sale.

--
http://www.firestreamer.com - NTBackup to DVD and DV


"Simon King" <sking@please.no.spam.whiskyalpha.com> wrote in message
news:cmqul9$efb$1$8302bc10@news.demon.co.uk...
> Hi,
>
> I have a USB device that Windows treats as a mouse. However, I would like
> to use it to control another application instead of moving the mouse
> pointer.
>
> I have been able to get the raw data from the device using the raw input
> API and WM_INPUT messages, so I can control the application, but
> unfortunately the mouse pointer moves as well. Is there any way that I can
> somehow prevent the default processing of the information? Do I need to
> write some sort of driver to intercept the device before it gets
> recognised as a mouse? I am hoping that there is a very simple obvious
> solution that I've missed.
>
> Thanks for any help,
>
> Simon



Re: Raw Input from Mouse-like HID device by Ray

Ray
Tue Nov 09 16:27:06 CST 2004

I've never tried this, but RegisterRawInputDevices claims to have a flag
called RIDEV_NOLEGACY that prevents the OS from generating the usual
mouse messages.

It certainly won't stop another app from using WM_INPUT or DirectX... so
if that's a concern, you might need to have a filter driver that your
app talks to to get the mouse messages directly, which avoids sending
them on up to MOUCLASS. (Remember to implement your own "ballistics"
function, because the raw "mickeys" that you get from mice aren't all
that usable for pointing).

You could also try using DirectInput and acquiring the device for
exclusive access. Again, not something I've tried, but it's documented
to work.

Simon King wrote:
> Hi,
>
> I have a USB device that Windows treats as a mouse. However, I would
> like to use it to control another application instead of moving the
> mouse pointer.
>
> I have been able to get the raw data from the device using the raw input
> API and WM_INPUT messages, so I can control the application, but
> unfortunately the mouse pointer moves as well. Is there any way that I
> can somehow prevent the default processing of the information? Do I need
> to write some sort of driver to intercept the device before it gets
> recognised as a mouse? I am hoping that there is a very simple obvious
> solution that I've missed.
>
> Thanks for any help,
>
> Simon

--
../ray\..

Re: Raw Input from Mouse-like HID device by Simon

Simon
Wed Nov 10 03:54:34 CST 2004

Ray Trent wrote:
> I've never tried this, but RegisterRawInputDevices claims to have a flag
> called RIDEV_NOLEGACY that prevents the OS from generating the usual
> mouse messages.

Thanks for the response. Unfortunately, this doesn't seem to work. I
think this prevents my application from receiving the usual mouse
messages, but it doesn't prevent the rest of the system from treating it
as a mouse. When I specify that flag and then use the device:

a) the mouse cursor moves as normal

b) my application no longer gets messages like WM_LBUTTONDOWN, so I
can't use either mouse to interact with it at all, and have to close it
using the keyboard.

When I call RegisterRawInputDevice, I don't think there's any way I can
specify to receive messages from the device that I want, but not from
the main mouse (because they have the same usage and usage page), so to
treat them differently, I would have to examine the WM_INPUT message to
see which device it came from. However, it's beginning to look like it
is too late by this stage because the system has already moved the mouse
pointer. I think I am probably going to have to look at writing a filter
driver, as suggested in another reply to my message.

Thanks for your help,

Simon

Re: Raw Input from Mouse-like HID device by Ray

Ray
Mon Nov 15 15:10:37 CST 2004

Have you tried using DirectInput?

Simon King wrote:
> Ray Trent wrote:
>
>> I've never tried this, but RegisterRawInputDevices claims to have a
>> flag called RIDEV_NOLEGACY that prevents the OS from generating the
>> usual mouse messages.
>
>
> Thanks for the response. Unfortunately, this doesn't seem to work. I
> think this prevents my application from receiving the usual mouse
> messages, but it doesn't prevent the rest of the system from treating it
> as a mouse. When I specify that flag and then use the device:
>
> a) the mouse cursor moves as normal
>
> b) my application no longer gets messages like WM_LBUTTONDOWN, so I
> can't use either mouse to interact with it at all, and have to close it
> using the keyboard.
>
> When I call RegisterRawInputDevice, I don't think there's any way I can
> specify to receive messages from the device that I want, but not from
> the main mouse (because they have the same usage and usage page), so to
> treat them differently, I would have to examine the WM_INPUT message to
> see which device it came from. However, it's beginning to look like it
> is too late by this stage because the system has already moved the mouse
> pointer. I think I am probably going to have to look at writing a filter
> driver, as suggested in another reply to my message.
>
> Thanks for your help,
>
> Simon

--
../ray\..

Re: Raw Input from Mouse-like HID device by Simon

Simon
Tue Nov 16 11:13:05 CST 2004

Ray Trent wrote:
> Have you tried using DirectInput?
>

Not so far, but now you've suggested it, I've found an interesting
comment in the 'Interaction with Windows' section of 'Understanding
DirectInput':

When using the system mouse in exclusive mode, DirectInput suppresses
mouse messages, and therefore Windows is unable to show the standard
cursor.

This sounds like it might do exactly what I want. Thanks for the suggestion.

Simon

Re: Raw Input from Mouse-like HID device by Simon

Simon
Wed Nov 17 08:40:00 CST 2004

I wrote:
> Ray Trent wrote:
>
>> Have you tried using DirectInput?
>>
>
> Not so far, but now you've suggested it, I've found an interesting
> comment in the 'Interaction with Windows' section of 'Understanding
> DirectInput':
>
> When using the system mouse in exclusive mode, DirectInput suppresses
> mouse messages, and therefore Windows is unable to show the standard
> cursor.
>
> This sounds like it might do exactly what I want. Thanks for the
> suggestion.
>

Unfortunately, the input from all mouse-like devices seems to be merged
by the time it gets to DirectInput. From the docs, in the section
'Creating a DirectInput Device':

If the computer has more than one mouse, input from all of them is
combined to form the system device. The same is true for multiple
keyboards.

So it looks like I can't distinguish between my USB device and the
normal mouse using that method.

Thanks anyway,

Simon

Re: Raw Input from Mouse-like HID device by Ray

Ray
Wed Nov 17 12:08:37 CST 2004

Hmmm. I always assumed that the "system mouse" abstraction was there as
a convenience for people just wanted to receive all mouse input.

Again, I've never tried this, but you may be able to open the device by
enumerating it with EnumDevices, and specifying the appropriate handle
rather than specifying GUID_SysMouse when you call CreateDevice.

However, it may be that the system doesn't let you open a mouse
seperately from DirectInput and only allows access via GUID_SysMouse...
not sure... Of course, in that case it may also be the case that getting
exclusive access also won't stop cursor motion...

Failing all of this, a mouse filter driver will probably be the only way
to go. More complicated, but you can do anything there.

Simon King wrote:
> I wrote:
>
>> Ray Trent wrote:
>>
>>> Have you tried using DirectInput?
>>>
>>
>> Not so far, but now you've suggested it, I've found an interesting
>> comment in the 'Interaction with Windows' section of 'Understanding
>> DirectInput':
>>
>> When using the system mouse in exclusive mode, DirectInput suppresses
>> mouse messages, and therefore Windows is unable to show the standard
>> cursor.
>>
>> This sounds like it might do exactly what I want. Thanks for the
>> suggestion.
>>
>
> Unfortunately, the input from all mouse-like devices seems to be merged
> by the time it gets to DirectInput. From the docs, in the section
> 'Creating a DirectInput Device':
>
> If the computer has more than one mouse, input from all of them is
> combined to form the system device. The same is true for multiple
> keyboards.
>
> So it looks like I can't distinguish between my USB device and the
> normal mouse using that method.
>
> Thanks anyway,
>
> Simon

--
../ray\..

Re: Raw Input from Mouse-like HID device by Simon

Simon
Thu Nov 18 04:35:10 CST 2004

Unfortunately, calling EnumDevices (passing DIEDFL_ALLDEVICES) only
gives two devices, the system keyboard and system mouse. If I pass
DIEDFL_INCLUDEALIASES, I get 3 mice and 3 keyboards, whether my USB HID
device is plugged in or not. Acquiring any one of them exclusively
causes the mouse cursor to disappear, and once it is gone I don't seem
to be able to generate normal mouse events even using the mouse_event
function.

I don't think I explained exactly what I wanted to do at the beginning
of this thread, so I'll try and do that now. I have two input devices -
a touch screen and a 'control stick' (I don't know what else to call it
- it's like the tiny joystick things that used to be on laptop keyboards
before touchpads became popular). Both are USB HID devices, and both
work fine when controlling the cursor normally.

However, I want the touchscreen to control the cursor, but the control
stick to control a different function in my application (although I also
want the ability to toggle this behaviour so that when necessary, the
control stick moves the mouse cursor)

Summary of what I have tried so far, (in case anyone other than Ray is
reading :-) ):

Raw Input: This would allow me to distinguish between the different
devices, but it wouldn't let me stop the control stick from moving the
mouse cursor.

DirectInput: This would not let me treat the devices independently
(because they both get merged into the 'system mouse' device)

I have even tried a nasty kludge using raw input, detecting that the
device that moved the mouse was the control stick, and moving the cursor
back to the original position again, but this made the cursor 'wobble'
on the screen, and was generally a bit nasty. It also probably wouldn't
work very well if the user tried to use both devices at the same time.

It's looking like I'm going to need a mouse filter driver so I'm
ordering the DDK, but since I've never done that before (and I imagine
it's not particularly easy) I was trying to explore all other avenues
first. Is there perhaps another newsgroup which would be more suitable
for this question?

Thanks again,

Simon

Ray Trent wrote:
> Hmmm. I always assumed that the "system mouse" abstraction was there as
> a convenience for people just wanted to receive all mouse input.
>
> Again, I've never tried this, but you may be able to open the device by
> enumerating it with EnumDevices, and specifying the appropriate handle
> rather than specifying GUID_SysMouse when you call CreateDevice.
>
> However, it may be that the system doesn't let you open a mouse
> seperately from DirectInput and only allows access via GUID_SysMouse...
> not sure... Of course, in that case it may also be the case that getting
> exclusive access also won't stop cursor motion...