How to suppress global mouse click events from windows?

后端 未结 1 1492
自闭症患者
自闭症患者 2021-01-16 18:37


I am developing a windows based application in which i want that whenever my application get started it should disable mouse click events outside the my application

相关标签:
1条回答
  • 2021-01-16 19:04

    This way it can be done. It uses the win API function BlockInput.

    NOTE: CTRL + ALT + DELETE enables the input again. But other mouse and keyboard input is blocked.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
    
    [return: MarshalAs(UnmanagedType.Bool)]
    [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
    public static extern void BlockInput([In, MarshalAs(UnmanagedType.Bool)]bool fBlockIt);
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.Show();
                //Blocks the input
                BlockInput(true);
                System.Threading.Thread.Sleep(5000);
                //Unblocks the input
                BlockInput(false); 
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题