Quiz.

01/03/2009 12:18 alexbigfoot#1
Hello.... i got an question. Is there any way that C# can use "right click" or press a key , like "F1" or any others...?
01/03/2009 12:28 _fobos_#2
Quote:
Originally Posted by alexbigfoot View Post
Hello.... i got an question. Is there any way that C# can use "right click" or press a key , like "F1" or any others...?
Send/PostMessage API can do that but as you're in CO Programming section that wont suit your needs, because that gets you send to clickjail.

Heres a quiek google find:
Code:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class Form1 : Form
{
   [DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
   public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);

   private const int MOUSEEVENTF_LEFTDOWN = 0x02;
   private const int MOUSEEVENTF_LEFTUP = 0x04;
   private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
   private const int MOUSEEVENTF_RIGHTUP = 0x10;

   public Form1()
   {
   }

   public void DoMouseClick()
   {
      //Call the imported function with the cursor's current position
      int X = Cursor.Position.X;
      int Y = Cursor.Position.Y;
      mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
   }

   //...other code needed for the application
}
That'll click on current position.
Google some more ^_~
01/03/2009 19:43 alexbigfoot#3
searched...nothing found...any other ideas?
01/04/2009 19:01 alexbigfoot#4
no one knows?
01/05/2009 06:14 Origonal#5
Quote:
Originally Posted by _fobos_ View Post
Send/PostMessage API can do that but as you're in CO Programming section that wont suit your needs, because that gets you send to clickjail.
I thought it was only click jail if u sent to a background window? If im wrong, bummer, if im not, then C# has the SendKeys package as well, which can be used for sending keyboard presses. [Only registered and activated users can see links. Click Here To Register...]
01/05/2009 18:30 alexbigfoot#6
ok...thx a lot but...how can i make the application to get what buttons are pressed in that moment...?
01/06/2009 19:15 _fobos_#7
Quote:
Originally Posted by Origonal View Post
I thought it was only click jail if u sent to a background window? If im wrong, bummer, if im not, then C# has the SendKeys package as well, which can be used for sending keyboard presses. [Only registered and activated users can see links. Click Here To Register...]
I've tried Send/Postmessage with client on top and got me clickjailed, tried on top and in background both same result :)
01/07/2009 07:12 Origonal#8
interesting, ive made a simple program to let me pot with shift key awhile ago, it may have been before clickjail was implemented (less than 2-3 months?) as i had no problems with it.
01/08/2009 14:16 alexbigfoot#9
how can i send mouse clicks like right click? i got all about sendkeys.
01/08/2009 22:05 alexbigfoot#10
nayway..nvm i`ll just use AHK.
01/08/2009 22:33 tao4229#11
If you want mouse clicks in C# one second...

Code:
public class Mouse
    {
        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetCursorPos(int X, int Y);

        [DllImport("user32.dll")]
        public static extern void mouse_event(uint dwFlags, long dx, long dy,
        uint dwData, IntPtr dwExtraInfo);

        public static void Move(ushort xpos, ushort ypos)
        {
            SetCursorPos((int)xpos, (int)ypos);
        }
        public static void LeftClick()
        {
            mouse_event(0x02, 0, 0, 0, IntPtr.Zero);
            mouse_event(0x04, 0, 0, 0, IntPtr.Zero);
        }
        public static void LeftClick(ushort xpos, ushort ypos)
        {
            Move(xpos, ypos);
            LeftClick();
        }
        public static void LeftDrag(ushort to_x, ushort to_y)
        {
            mouse_event(0x02, 0, 0, 0, IntPtr.Zero);
            Move(to_x, to_y);
            mouse_event(0x04, 0, 0, 0, IntPtr.Zero);
        }
        public static void RightClick()
        {
            mouse_event(0x08, 0, 0, 0, IntPtr.Zero);
            mouse_event(0x10, 0, 0, 0, IntPtr.Zero);
        }
        public static void RightClick(ushort xpos, ushort ypos)
        {
            Move(xpos, ypos);
            RightClick();
        }
        public static void RightDrag(ushort to_x, ushort to_y)
        {
            mouse_event(0x08, 0, 0, 0, IntPtr.Zero);
            Move(to_x, to_y);
            mouse_event(0x10, 0, 0, 0, IntPtr.Zero);
        }
        public static void LeftHold(TimeSpan wait)
        {
            mouse_event(0x02, 0, 0,0, IntPtr.Zero);
            System.Threading.Thread.Sleep(wait);
            mouse_event(0x04, 0, 0, 0, IntPtr.Zero);
        }
        public static void LeftHold(int millisecondwait)
        {
            LeftHold(new TimeSpan(0, 0, 0, 0, millisecondwait));
        }
    }
I made this off a ton of examples from google a while ago.