473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to move the mouse around in vb.net

Hi,

I'm trying to use the following user32 API's in vb.net:
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx
As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As
Long)

Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y
As Long) As Long

When I use the mouse_event to move the mouse to another location, it does
not seem to work correctly. However in VB6, the above APIs work perfectly.

For example, I do the following:

SetCursorPos(640, 512)

Mouse_Event(MOUSEEVENTF_MOVE, 100, 100, 0, 0)

What happens is that instead of moving to location (740, 612) the mouse goes
to location (640, 612). The dx argument somehow is not understood.

Can anyone tell me what else I can do? Or is there an equivalent .net
function that is available to do the same thing instead of using user32 API.

Thanks for the help,

Glenn


May 5 '06 #1
2 26338
"Glenn Palomar" <gl***********@autodesk.com> schrieb:
I'm trying to use the following user32 API's in vb.net:
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal
dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As
Long)

Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal
Y As Long) As Long


The declarations are invalid for VB.NET. Use these instead:

\\\
Private Declare Sub mouse_event Lib "user32.dll" ( _
ByVal dwFlags As Int32, _
ByVal dx As Int32, _
ByVal dy As Int32, _
ByVal cButtons As Int32, _
ByVal dwExtraInfo As Int32 _
)

Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal X As Int32, _
ByVal Y As Int32 _
) As Boolean
///

Note that 'Cursor.Position' can be used in VB.NET instead of 'SetCursorPos'.
'Long' must be changed to 'Int32' in constant declarations too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 5 '06 #2
Thanks. Now, it's working fine... Glenn

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O9**************@TK2MSFTNGP03.phx.gbl...
"Glenn Palomar" <gl***********@autodesk.com> schrieb:
I'm trying to use the following user32 API's in vb.net:
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal
dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo
As Long)

Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal
Y As Long) As Long


The declarations are invalid for VB.NET. Use these instead:

\\\
Private Declare Sub mouse_event Lib "user32.dll" ( _
ByVal dwFlags As Int32, _
ByVal dx As Int32, _
ByVal dy As Int32, _
ByVal cButtons As Int32, _
ByVal dwExtraInfo As Int32 _
)

Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal X As Int32, _
ByVal Y As Int32 _
) As Boolean
///

Note that 'Cursor.Position' can be used in VB.NET instead of
'SetCursorPos'. 'Long' must be changed to 'Int32' in constant declarations
too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: meganrobertson22 | last post by:
Hi- I'd like to try to have text displayed when I move my mouse over a command button. For example: let's say I have a form with 3 different command buttons. Each command button launches a...
1
by: suhas | last post by:
Hi, I have an MDI app that allows user to create flowcharts. User can drag flowchart objects (squares, rectangles, elipses, etc) from the toolbar and put on a form. They should be able to move...
2
by: Jurate | last post by:
I want my window not to have title bar, but then the problem arises, how to move such a window. Is it possible to make window move by moving mouse anywhere on that window? -- Jurate
1
by: mihyon | last post by:
Dear all, I tried to maximize dialog in dialog based application. I used 'ShowWindow(SW_MAXIMIZE);' and I tried to move dialog around. I used
5
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event...
2
by: p_cranfield | last post by:
Hi I am trying to work out how to move controls contained within a user controls at design time using the mouse in the IDE. Consider the following: Project A contains usercontrol1 with...
6
by: Rob | last post by:
This is a curious problem. It seems like it should be quite easy. Of course a timer is used to determine when form should be closed, but how do you consistently reset the timer when the mouse is...
0
by: hmm | last post by:
Hi all I have two problems: Problem #1: I'm using a .NET Form with the property 'FormBorderStyle' set to 'None'. The idea is to completely cover the area of that Form with a UserControl. In...
7
by: Michael R | last post by:
It's an interesting question, as I see it. I have a form, in which there are a few command buttons, which change color when the mouse is on top of them (On Mouse Move). Now, I want the color to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.