如何确定是否在Silverlight应用程序中切换了大写锁定? [英] How to determine if the Caps Lock is toggled in a Silverlight Application?

查看:77
本文介绍了如何确定是否在Silverlight应用程序中切换了大写锁定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Silverlight应用程序的登录屏幕中,我需要确定是否切换了Caps Lock。通过处理KeyUp或KeyDown事件,这很容易,但是,即使没有按下任何键,如何确定是打开还是关闭呢?

In a Silverlight application's log in screen, i need to determine if Caps Lock is toggled. This is easy enough by handling the KeyUp or KeyDown event, however how does one determine if it is toggled on or off even if a key hasn't been pressed?

我要这样做的原因是,如果用户在Silverlight应用程序运行时没有按Caps Lock键,而是在进入登录屏幕之前就切换了Caps Lock?我仍然需要警告他们大写锁定已打开。

The reason I want todo this is what if the user doesn't press Caps Lock while the Silverlight application is running, but rather they toggled it before they even got to the login screen? I need to still warn them that caps Lock is on.

显然在Silverlight中无法处理非托管代码,因此以下操作无效。

Apparently handling unmanaged code is not possible in Silverlight so the following doesn't work.

[DllImport( user32.dll)]
内部静态外部简短GetKeyState(int keyCode);

[DllImport("user32.dll")] internal static extern short GetKeyState(int keyCode);

推荐答案

检测CAPS锁定的方法是检查KeyValue和KeyEventArgs的移位。

如果KeyValue是(例如) A,但Shift为false,然后打开CAPS LOCKS。

不是最好的方法,但是它的 Ajax应用程序的运行方式

The way to detect CAPS LOCKS is to check the KeyValue and the Shift of KeyEventArgs.
if the KeyValue is (for example) 'A' but the Shift is false then the CAPS LOCKS is on.
Not the best way but its how ajax applications has been doing it.

这篇关于如何确定是否在Silverlight应用程序中切换了大写锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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