获取键盘状态在WPF应用程序的主方法启动过程中 [英] Get keyboard status in WPF Application in Main-Method during startup

查看:123
本文介绍了获取键盘状态在WPF应用程序的主方法启动过程中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中的静态无效的主要方法,我想,以确定是否像Alt键或Ctrl键被按下,然后开始在一些实物期权模式的应用程序启动。我怎样才能找出是否启动时按下某个键?

When my application starts up in the static void Main method I want to determine if a key like Alt or Ctrl is pressed and then start the Application in some kind of Option-Mode. How can I find out if a key is pressed during startup?

我发现了一些样本已,但他们都导入Windows动态链接库,这是我不想做的事。

I found some samples already but they all import a windows dll, something I don't want to do.

推荐答案

使用Keyboard.IsKeyDown()静态方法将帮助你检查你感兴趣的按键的状态

Use Keyboard.IsKeyDown() static method will help you to check the state of the keys you're interested in.

if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)
       || Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt) )
{
    //Load in a special mode
}
else
{
    //Load standard mode
}

这篇关于获取键盘状态在WPF应用程序的主方法启动过程中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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