728x90
728x170

마우스를 후킹하는 방법

 

Nuget 에서 MouseKeyHook 를 설치

 

프로그램 생성자나 원하는 후킹시점에 아래 처럼 코딩

 

using System.Windows.Forms;

 

using Gma.System.MouseKeyHook;

 

namespace MouseHooking

{

    public partial class MainForm : Form

    {

        public MainForm()

        {

            InitializeComponent();

 

            Hook.GlobalEvents().MouseDown += (s, e) =>

            {

                this.hookTextBox.AppendText($"Mouse {e.Button} Down / ");

            };

 

            Hook.GlobalEvents().MouseDoubleClick += (s, e) =>

            {

                this.hookTextBox.AppendText($"Mouse {e.Button} button double clicked / ");

            };

 

            Hook.GlobalEvents().MouseWheel += (s, e) =>

            {

                this.hookTextBox.AppendText($"Mouse wheel / ");

            };

 

            Hook.GlobalEvents().MouseDragStarted += (s, e) =>

            {

                this.hookTextBox.AppendText($"Mouse drag start / ");

            };

 

            Hook.GlobalEvents().MouseDragFinished += (s, e) =>

            {

                this.hookTextBox.AppendText($"Mouse drag finish / ");

            };

        }

    }

}

 

 

프로그램을 띄우면 마우스가 어디있건 움직임을 후킹한다.

 

728x90
그리드형
Posted by kjun.kr
,