-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.

5
  • Please be a little more specific. What do you want this code to do? Commented Jun 20, 2014 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. Commented Jun 20, 2014 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
    Commented Jun 20, 2014 at 14:22
  • possible duplicate of VB.NET event listener for click outside a form Commented Jun 20, 2014 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
    Commented Jun 20, 2014 at 18:22

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.