• Welcome to Valhalla Legends Archive.
 

[vb.net]Sending a click to the active window

Started by SweatyOgre, December 24, 2004, 04:22 PM

Previous topic - Next topic

SweatyOgre

How could I send a click to the active window? Someone told me that the SendInput command did it, but I dont quite understand how it works.

MyndFyre


Imports System.Runtime.InteropServices

Public Class Mouse

Public Declare Function SendInput Lib "user32" _
         Alias "SendInputW" (Integer nInputs, _
<MarshalAs(UnmanagedType.LPArray)>_
         INPUT pInputs(), _
         Integer cbSize)
) As Integer

End Class

<StructLayout(LayoutKind.Explicit)> _
Public Struct INPUT
  <FieldOffset(0)>_
   Public mi As MOUSEINPUT
  <FieldOffset(0)>_
  Public ki As KEYBOARDINPUT
  <FieldOffset(0)>_
  Public hi As HARDWAREINPUT
End Struct

' Since you only want the mouse input, I'm only converting that one:
<StructLayout(LayoutKind.Explicit)>_
Public Struct MOUSEINPUT
  <FieldOffset(0)>_
  Public dx As Integer
  <FieldOffset(4)>_
  Public dy As Integer
  <FieldOffset(8), MarshalAs(UnmanagedType.U4)>_
  Public mouseData As Integer
  <FieldOffset(12), MarshalAs(UnmanagedType.U4)>_
  Public dwFlags As MouseEventFlags
  <FieldOffset(16), MarshalAs(UnmanagedType.U4)>_
  Public time As Integer
  <FieldOffset(20)>_
  Public dwExtraInfo As IntPtr
End Struct

' I said there is a MouseEventFlags enumeration.  This is based on #defines in winuser.h.  It is:
<Flags()>_
Public Enum MouseEventFlags
   MOUSEEVENTF_MOVE = &H0001     ' mouse move */
   MOUSEEVENTF_LEFTDOWN = &H0002    ' left button down */
   MOUSEEVENTF_LEFTUP = &H0004      ' left button up */
   MOUSEEVENTF_RIGHTDOWN = &H0008       ' right button down */
   MOUSEEVENTF_RIGHTUP = &H0010        ' right button up */
   MOUSEEVENTF_MIDDLEDOWN = &H0020      ' middle button down */
   MOUSEEVENTF_MIDDLEUP = &H0040        ' middle button up */
   MOUSEEVENTF_XDOWN = &H0080        ' x button down */
   MOUSEEVENTF_XUP = &H0100          ' x button down */
   MOUSEEVENTF_WHEEL = &H0800          ' wheel button rolled */
   MOUSEEVENTF_VIRTUALDESK = &H4000          ' map to entire virtual desktop */
   MOUSEEVENTF_ABSOLUTE = &H8000        ' absolute move */
End Enum


That is the declaration set for the Windows API in Visual Basic .NET.  If you have questions as to how to use it, refer to the MSDN Library.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.