-3

In Visual Studio 2008, how do I implement this code?

If MouseButtons() = Windows.Forms.MouseButtons.Left Then

    SendKeys.Send("{3}")
    SendKeys.SendWait("{1}")
End If

When I press the left button of the mouse, I want it to send 3 & 1 to my Game.

I'll be using this code for a game.

VeiLuxe
  • 7
  • 1
  • Please be a little more specific. What do you want this code to do? – Eduardo Briguenti Vieira Jun 20 '14 at 14:18
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. – Eduardo Briguenti Vieira Jun 20 '14 at 14:19
  • When I click left mouse buton, my program press 3 & 1. And I click left mouse button not on form, but out of form... – VeiLuxe Jun 20 '14 at 14:22
  • possible duplicate of [VB.NET event listener for click outside a form](http://stackoverflow.com/questions/19210404/vb-net-event-listener-for-click-outside-a-form) – Hans Passant Jun 20 '14 at 14:50
  • I still don't understand what "send 3" is supposed to mean. On its own it is not clear, and it could have been intended to mean any one of several things, so please be much more specific. – ClickRick Jun 20 '14 at 18:22

1 Answers1

0

You can get the mouse click with this.

Add a timer "for my code call it DeskClick" Add a textbox called ShowMouseClick "so you can check"

Private Declare Function GetAsyncKeyState Lib "user32" _
 (ByVal vKey As Long) As Integer

Private Const LBUTTON = &H1
Private Const RBUTTON = &H2

Private Sub DeskClick_Tick(sender As Object, e As EventArgs) Handles DeskClick.Tick
    If GetAsyncKeyState(LBUTTON) Then
        ShowMouseClick.Text = "Left Click"
    ElseIf GetAsyncKeyState(RBUTTON) Then
        ShowMouseClick.Text = "Right Click"
    Else
        ShowMouseClick.Text = ""
    End If
End Sub

you also need to turn of PInvokeStackImbalance Go to Debug then select Exceptions Then MDA and deselect PInvokeStackImbalance

enter image description here enter image description here

Maybe this is not the best way but it works perfect in my app Whit out any problem


To capture the event and do something

  Private Sub ShowMouseClick_TextChanged(sender As Object, e As EventArgs) Handles ShowMouseClick.TextChanged
    If ShowMouseClick.Text = "Left Click" Then

  TextBox1.Focus()
  SendKeys.Send("{3}")
  SendKeys.SendWait("{1}")

    End If
  End Sub
Creator
  • 1,502
  • 4
  • 17
  • 30