是否检测到在应用程序启动时按住Ctrl键? [英] Detecting Ctrl key being held down on application startup?

查看:49
本文介绍了是否检测到在应用程序启动时按住Ctrl键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们的WPF应用程序启动时,它使用Single Sign On登录.为了允许测试人员模拟其他用户,我们希望检测到启动时按住Control键,并弹出一个登录对话框.

When our WPF application starts, it uses Single Sign On to log in. To allow testers to simulate other users, we'd like to detect the Control button being held down on startup, and pop up a login dialog.

推荐答案

这是我在WPF应用程序中使用的功能,用于检查主窗口的构造函数中是否按住了控制键.它使用 System.Windows.Input.Keyboard

This is what I use in a WPF app to check if the control key is being held down in the constructor of the main Window. It uses System.Windows.Input.Keyboard

if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
    PromptForMarketSelection();

编辑-修正了Coincoin指出的错误

EDIT - corrected bug pointed out by Coincoin

这篇关于是否检测到在应用程序启动时按住Ctrl键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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