[TUT] The Mouse [VB] - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19) +---- Thread: [TUT] The Mouse [VB] (/showthread.php?tid=6271) Pages:
1
2
|
[TUT] The Mouse [VB] - RaZoR03 - 04-15-2010 I leeched this from here! In this tutorial I will show how to get the actions made by the mouse but also show you how to control the mouse. Its Location To get the position where the mouse is on the screen you can use MousePosition, you will then get the mouse's position of the screen as a point, so to get the X and Y values you just do something like this: Code: MessageBox.Show("X: " & MousePosition.X & " Y: " & MousePosition.Y) But you can do the same thing with Cursor.Position, like so: Code: MessageBox.Show("X: " & Cursor.Position.X & " Y: " & Cursor.Position.Y) And Cursor.Position is not readonly as MousePosition is, this means you can move the mouse cursor to a special point of the screen like this: Code: Cursor.Position = New Point(250, 250) Get which button was used When using the MouseDown event: Code: Private Sub frmMain_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick on something we can check which button that was press by using: Code: e.Button.ToString Since e.Button is an Enum with all the different buttons you can also do like this: Code: Private Sub frmMain_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick Scrolling You can also get the direction and how much you scrolled with the mouse wheel by using the MouseWheel event: Code: Private Sub frmMain_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel .Delta is how much you scrolled, this is depending on the options in the control panel about mouse wheel scrolling. So we can't be sure what these values will be, but the good thing is that scrolling ups is always positive and scrolling down is negative. So therefor we can do like this: Code: Private Sub frmMain_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel Simulating mouse clicks It's also possible to simulate mouse clicks from button 1,2 and 3 (Left, Right and Middle). To do this we first need to declare the mouse clicking sub: Code: Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer) Then we create another sub to easier use it: Code: Private Sub Mouse_Click(ByVal button As Integer, ByVal state As String) So if we now want to simulate a click from button 2(Right mouse button) we'll do like this: Code: Mouse_Click(2, "down") RE: [TUT] The Mouse [VB] - Kewlz - 04-15-2010 ur code /code did not wrk RE: [TUT] The Mouse [VB] - void. - 04-17-2010 He probably ripped this. RE: [TUT] The Mouse [VB] - Prone - 04-17-2010 This is ripped, jah? RE: [TUT] The Mouse [VB] - TurB0 - 04-17-2010 This is nice Thank you RE: [TUT] The Mouse [VB] - RaZoR03 - 04-18-2010 (04-15-2010, 12:46 PM)Mr.Kewl Wrote: ur code /code did not wrk Its working now,Sry RE: [TUT] The Mouse [VB] - Carb0n F1ber - 04-18-2010 Ripped from --> http://forum.codecall.net/vb-tutorials/22383-mouse-visual-basic-net.html RE: [TUT] The Mouse [VB] - Julie - 04-18-2010 Nice tutorial, thanks ! Keep it up RE: [TUT] The Mouse [VB] - ShuTdown - 04-24-2010 Nice, But I have seen tutorial like this on another forums. RE: [TUT] The Mouse [VB] - Elektrisk - 04-24-2010 (04-24-2010, 07:14 AM)ShuTdown Wrote: Nice, But I have seen tutorial like this on another forums. Yes. He leeched his tutorials without giving credits, which is why he is banned |