title: How to simulate mouse click?
body: <p>I'm trying to make a program to click with keyboard like in <a href="http://osu.ppy.sh" rel="nofollow noreferrer">Osu!</a>.</p>
  
  <p>I've tried <code>SendKeys()</code>, <code>RaiseMouseEvent()</code> and <code>OnMouseClick()</code>. Now I'm trying this and can't get anything to work.</p>
  
  <p>The error I keep getting is:</p>
  
  <blockquote>
    <p><a href="http://puu.sh/3tBQb.png" rel="nofollow noreferrer">PInvoke restriction: cannot return variants.</a></p>
  </blockquote>
  
  <pre><code>Public Class Form1
      Dim onn As Boolean = False
      Declare Function mc Lib "user32.dll" Alias "mouse_event" (flag, x, y, button, extra)
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          If Not onn Then
              Button1.Text = "Off"
              Label1.Text = "Status: On"
              onn = True
          ElseIf onn Then
              Button1.Text = "On"
              Label1.Text = "Status: Off"
              onn = False
          End If
      End Sub
      Private Sub Form1_KeyPress1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
          If onn And (e.KeyChar = "Z" Or e.KeyChar = "X" Or e.KeyChar = "z" Or e.KeyChar = "x") Then
              mc(&amp;H2, 0, 0, 0, 0)
              mc(&amp;H4, 0, 0, 0, 0)
          End If
      End Sub
  End Class
  </code></pre>