拦截每一次鼠标单击以进入WPF应用程序 [英] Intercept every mouse click to WPF application

查看:54
本文介绍了拦截每一次鼠标单击以进入WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望拦截WPF应用程序中的每一次鼠标单击.使用命令路由机制似乎应该很容易,但是对不起,我什么都没找到.

I'm looking to intercept every mouse click in my WPF application. Seems this should be easy with the command routing mechanism, but sorry I'm not finding anything.

我的应用程序实现了几个安全级别,并且如果没有人在x分钟内与该应用程序进行交互(单击),则要求自动恢复到最严格的级别.我的计划是添加一个计时器,该计时器将在x分钟后过期并调整安全级别.每次在应用程序中单击鼠标都会重置计时器.

My application implements several security levels, and has the requirement to automatically revert to the most restrictive level if no one interacts with (clicks) the application in x minutes. My plan is to add a timer that expires after x minutes and adjusts the security level. Each mouse click into the application will reset the timer.

推荐答案

您可以注册一个类处理程序:

You can register a class handler:

public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            EventManager.RegisterClassHandler(typeof(Window), Window.PreviewMouseDownEvent, new MouseButtonEventHandler(OnPreviewMouseDown));

            base.OnStartup(e);
        }

        static void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            Trace.WriteLine("Clicked!!");
        }
    }

这将处理在应用程序中创建的任何Window上的任何 PreviewMouseDown 事件.

This will handle any PreviewMouseDown event on any Window created in the application.

这篇关于拦截每一次鼠标单击以进入WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆