• 鼠标单击右击双击简单功能的实现


            在糊里糊涂的情况下,我实现了鼠标的左击右击和双击,感觉什么都不知道似地,貌似HOOK里面有点复杂,搞不清楚诶,那位高人能指点哈子。最好了。
            FORM1.CS代码
        
    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Windows.Forms;


    namespace hook鼠标控制
    {
        
    public partial class Form1 : Form
        
    {
            hook鼠标控制.MouseHook mouse;
            
    public Form1()
            
    {
                InitializeComponent();
                mouse 
    = new MouseHook();
                mouse.OnMouseActivity 
    += new MouseEventHandler(this.mouse_OnMouseActivity);

            }


            [Flags]
            
    enum MouseEventFlag : uint
            
    {
                Move 
    = 0x0001,
                LeftDown 
    = 0x0002,
                LeftUp 
    = 0x0004,
                RightDown 
    = 0x0008,
                RightUp 
    = 0x0010,
                MiddleDown 
    = 0x0020,
                MiddleUp 
    = 0x0040,
                XDown 
    = 0x0080,
                XUp 
    = 0x0100,
                Wheel 
    = 0x0800,
                VirtualDesk 
    = 0x4000,
                Absolute 
    = 0x8000
            }



            [DllImport(
    "user32.dll ", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
            
    public static extern bool SetDoubleClickTime(uint uInterval);

            [DllImport(
    "user32.dll")]
            
    static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);

            [DllImport(
    "user32.dll")]
            
    static extern bool SetCursorPos(int X, int Y);

            
    int i = 0;
            
    int j = 0;
            
    private void button1_Click(object sender, EventArgs e)
            
    {
                
    //mouse.Start();
                i = Convert.ToInt16(tb_times.Text.Trim());
                z 
    = 0;
                j 
    = 0;

                
    this.time_timer.Interval = Convert.ToInt16(this.tb_time.Text.Trim());
                
    this.time_timer.Start();

            }


            
    private void mouse_OnMouseActivity(object sender, MouseEventArgs e)
            
    {
                
    this.lb_x.Text = e.X.ToString();
                
    this.lb_y.Text = e.Y.ToString();
                
    this.lb_z.Text = e.Button.ToString();
            }


            
    private void button2_Click(object sender, EventArgs e)
            
    {
                Application.Exit();
            }


            
    private void Form1_Load(object sender, EventArgs e)
            
    {

            }


            
    private void button3_Click(object sender, EventArgs e)
            
    {
                lb_xx.Text 
    = lb_x.Text;
                lb_yy.Text 
    = lb_y.Text;
            }


            
    private void time_timer_Tick(object sender, EventArgs e)
            
    {
                j
    ++;
                
    if (j > i)
                    
    this.time_timer.Stop();
                
    if (this.cmb_clickWay.Text == "左击")
                
    {
                    SetCursorPos(Convert.ToInt16(
    this.lb_xx.Text.Trim()), Convert.ToInt16(this.lb_yy.Text.Trim()));
                    mouse_event(MouseEventFlag.LeftDown, 
    000, UIntPtr.Zero);
                    mouse_event(MouseEventFlag.LeftUp, 
    000, UIntPtr.Zero);
                }

                
    else if (this.cmb_clickWay.Text == "右击")
                
    {
                    SetCursorPos(Convert.ToInt16(
    this.lb_xx.Text.Trim()), Convert.ToInt16(this.lb_yy.Text.Trim()));
                    mouse_event(MouseEventFlag.RightDown, 
    000, UIntPtr.Zero);
                    mouse_event(MouseEventFlag.RightUp, 
    000, UIntPtr.Zero);
                }

                
    else if (this.cmb_clickWay.Text == "双击")
                
    {
                    SetCursorPos(Convert.ToInt16(
    this.lb_xx.Text.Trim()), Convert.ToInt16(this.lb_yy.Text.Trim()));
                    
    this.doubleclick_timer.Start();

                }

            }

            
    int z = 0;
            
    private void doubleclick_timer_Tick(object sender, EventArgs e)
            
    {
                z
    ++;
                
    if (z == 3)
                    doubleclick_timer.Stop();
                mouse_event(MouseEventFlag.LeftDown, 
    000, UIntPtr.Zero);
                mouse_event(MouseEventFlag.LeftUp, 
    000, UIntPtr.Zero);

            }


        }

    }

    事件代码 网络上自己找的。
    Code
  • 相关阅读:
    备注下Windows可能会用到的运行命令
    SQL2008R2 收缩数据库问题
    转:SQL Server服务器名称与默认实例名不一致的修复方法
    mac下初始化eclipse的安卓开发ndk开发环境
    eclipse android ndk 提示Type 'JNIEnv' could not be resolved 等信息解决办法
    eclipse ndk 配置和简单开发demo
    ubuntu15.10运行android studio出错unable to run mksdcard sdk tool
    Pavilion M4-1016TX 加装固态硬盘(SSD)+UEFI+GPT安装WIN8.1
    package.json和package-lock.json的区别
    Vue生命周期中mounted和created的区别
  • 原文地址:https://www.cnblogs.com/itgmhujia/p/1103827.html
Copyright © 2020-2023  润新知