应用程序启动期间的键盘修饰符 [英] Keyboard modifiers during application startup

查看:58
本文介绍了应用程序启动期间的键盘修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想捕获在应用程序启动期间是否按下了修饰键(以确定是全屏显示还是窗口显示).

I wanted to capture whether a modifier key was being pressed during application startup (to determine fullscreen or windowed).

在主窗口构造函数中,我尝试检查

In the main window constructor I tried checking the Keyboard.Modifiers enum to see if Shift is down. It always showed 'None'.

因此,我尝试通过启动 DispatcherTimer 并检查其Tick事件是否移位.多数民众赞成在似乎很好.

So I tried a different approach by starting off a DispatcherTimer and checking for shift in its Tick event. Thats seems to work fine.

问题是,这是最好的(唯一的)方法吗?为什么修饰符在窗口构造函数中未返回正确的值?

Question is, is this the best (only) way to do this? And why does the modifier not return the correct value in the window constructor?

推荐答案

Keyboard.Modifiers是正确的类/属性.

我建议在处理程序中检查FrameworkElement.Loaded事件的修饰符.

I would suggest checking the modifiers in a handler for the FrameworkElement.Loaded event.

InitializeComponent()之后的Window构造函数中:

this.Loaded += new RoutedEventHandler(Window_Loaded);

并且:

void Window_Loaded(object sender, RoutedEventArgs e)
{
    // Examine Keyboard.Modifiers and set fullscreen/windowed
    if ((Keyboard.Modifiers & ModifierKeys.Shift) > 0)
    {
        //SetFullscreen();
    }
}

这篇关于应用程序启动期间的键盘修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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