Réponse acceptée !
Bon alors en fait je connaissais déjà la solution pour l'avoir donnée il y a 2 mois environ, mais je préfèrais te laisser chercher un peu avant.
Hein ? Trou de mémoire ? Meuh non

(
http://www.csharpfr.com/forum.v2.aspx?ID=389913)
Dans le cas qui nous interesse ça donne (vite fait, je te laisse adapter comme il faut derriere) :
APIs :
#region API: methodes
[DllImport("user32.dll")]
private static extern int SendInput(
int nInputs,
ref INPUT pInputs,
int cbSize
);
[DllImport("user32.dll")]
private static extern IntPtr GetMessageExtraInfo();
#endregion
#region API: constantes
private const uint INPUT_MOUSE = 0;
private const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
private const uint MOUSEEVENTF_LEFTUP = 0x0004;
#endregion
#region API: structures
[StructLayout(LayoutKind.Explicit)]
private struct INPUT
{
[FieldOffset(0)]
public uint type;
[FieldOffset(4)]
public MOUSEINPUT mi;
}
private struct MOUSEINPUT
{
public int dx;
public int dy;
public uint mouseData;
public uint dwFlags;
public uint time;
public IntPtr dwExtraInfo;
}
#endregion
Exemple d'utilisation (ça fait un clic sur mon menu démarrer, wahou :p) : Cursor.Position =
new Point(10, 1010);
// clic
INPUT input =
new INPUT();
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1,
ref input, Marshal.SizeOf(input));
input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1,
ref input, Marshal.SizeOf(input));
Cocoricoooooooo !!!!
coq
MVP Visual C#