How to change Mouse behavior

  • Thread starter Carlos García-Carazo
  • Start date
C

Carlos García-Carazo

Hello,
I am working on a C# application for an industrial machine, using Windows
Forms,
where the user could look at the screen from a 90 degree rotated position,
like he
could turn the monitor to leave it standing on its left (or right) side.

There are many ways to show a "turned" interface in this case, but the
problem is that when he moves the mouse right, in a turned screen the mouse
cursor goes down (or up), when he moves it up the cursor goes left, and so
on.

So I need to swap the mouse Input axis at OS level, or at least inside my
application window. I need the X input be the Y (or negative Y) and vice
versa.

I believe this could be a common problem for several developers, so there
should be some kind of utility or sample code out there, but I haven't found
anything.
I have tried to capture and change the events coming through .NET framework,
but the mouse cursor is still managed from Windows OS. Also I haven't found
anything
useful in Open Source DLL's to jump to kernel-mode (Ring0) and change the
mouse hardware registers.

Is there some suggestion or should I write a mouse driver as the only
solution possible?

Thx,
Carlos
 
B

Bob Powell [MVP]

Take a look at the Windows Forms Tips and Tricks article on how to backtrack
the mouse.

This shows how you can use the transform that the graphics are displayed in
to translate the mouse position to the virtual page.

It works for zooms and rotations, in fact any transform.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
C

Carlos García-Carazo

Sorry, but I didn't explain it correctly.

My problem is:
1. Take the monitor in your hands, turn it 90 degrees to the left and
carefully leave it over the table.

2. Move the mouse to the right. I need the windows mouse cursor to go
that way, but it moves up.

3. The user can't click anything because it is very difficult to point the mouse
arrow at the desired target.

Looking at your code, your take the mouse coordinates from the MouseMove
event and transform it to draw the screen. This is correct, but it is only the half
of my problem.

The other half is that I need to move the mouse arrow in the transformed space.
In your example, the arrow icon of the mouse (managed by windows)
should move at a step of 2 when the zoom factor is 200%, to solve my problem.

I need to capture the movement of the mouse and transform it before it applies to
the Windows arrow, so the user can point with it from its transformed space.

I know this is a weird thing, but it makes sense if you imagine a worker looking at
the image from a DLP projector over a working table, moving himself
round the projection, and handling a wireless mouse from this "rotated" position.

Regards,
Carlos
 
A

Ashish Das

and how do you know that monitor is rotated?

as far as changing the movement of mouse goes driver for the monitor handles
the virtual x and y axis with the change in the position (angle) of the
screen (with the help of OS as resolution is still a matter to take care).
if you have access to the position of hardware you can write a driver for
that. as far as C# application goes, it never knows how it is displayed at
the other end.
 
B

Bob Powell [MVP]

I think that you need to be dealing with the low-level system and not what's
happening at an application level.

You cannot have the OS thinking it's in one orientation and a single
application thinking it's in another.

I suggest that you talk to people in the DDK newsgroup.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
C

Carlos García-Carazo

Ashish Das said:
and how do you know that monitor is rotated?

We use a special mouse with many buttons. The projector shows a screen on a large piece
of leather, over a cutting machine. The idea is that the user can work from different angles
looking at the projection (it is a CAD/CAM application) and clicking a special button
for each position. This way we can know that the entire view is rotated and we must
invert the mouse input.
as far as changing the movement of mouse goes driver for the monitor handles
the virtual x and y axis with the change in the position (angle) of the
screen (with the help of OS as resolution is still a matter to take care).
if you have access to the position of hardware you can write a driver for
that. as far as C# application goes, it never knows how it is displayed at
the other end.

OK, so this is beyond the scope of C#. That is what I want to know.
Thanks.
 
C

Carlos García-Carazo

Bob Powell said:
I think that you need to be dealing with the low-level system and not what's
happening at an application level.

You cannot have the OS thinking it's in one orientation and a single
application thinking it's in another.

I suggest that you talk to people in the DDK newsgroup.

I was thinking about writing a driver, but I am not an expert on VS.NET
so I needed a confirmation of this. I saw an article about accesing IO ports
from C# using a DLL (in Code Project website) and this "forced" me to ask
first.

Many thanks, now going to DDK level :)
Carlos.

PD: the article of your website is good, also the idea of switching between C#
and Visual Basic versions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top