如何确定 Silverlight 应用程序中是否切换了大写锁定?
在 Silverlight 应用程序的登录屏幕中,我需要确定是否切换了 Caps Lock。 通过处理 KeyUp 或 KeyDown 事件,这很容易,但是即使没有按下某个键,如何确定它是打开还是关闭呢?
我想要这样做的原因是,如果用户在 Silverlight 应用程序运行时没有按 Caps Lock 键,而是在进入登录屏幕之前就切换了它,该怎么办? 我仍然需要警告他们大写锁定已打开。
显然,在 Silverlight 中处理非托管代码是不可能的,因此以下内容不起作用。
[DllImport("user32.dll")] 内部静态外部短 GetKeyState(int keyCode);
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?
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.
Apparently handling unmanaged code is not possible in Silverlight so the following doesn't work.
[DllImport("user32.dll")]
internal static extern short GetKeyState(int keyCode);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检测CAPS LOCKS的方法是检查KeyValue和KeyEventArgs的Shift。
如果 KeyValue 为(例如)“A”但 Shift 为 false,则大写锁定打开。
不是最好的方法,但它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.
据我所知你不能。 您也许能够在应用程序中拾取向上和向下的按键,但如果用户离开您的应用程序,您将不知道它处于什么状态。
我没有注意到 SL3 中有任何额外的支持,但我不能说我一直在特别寻找它。
As far as I know you can't. You might be able to pickup on the key going up and down from your app, but you won't know what state it was in if the users leave your app.
I've not noticed any additional supprt for it in SL3, but I can't say I've been particularly looking for it.
Silverlight 不支持在客户端调用 Win32 DLL。 所以你不能用上面的技巧来测试Capslock键是否被按下。 您是否尝试过使用 KeyDown 事件并测试系统键? 我没有这样做,但这是一种预感。
Silverlight does not support invoking Win32 DLLs on the client side. So you can't use the above technique to test whether the Capslock key is pressed. Have you tried using the KeyDown event and testing for System keys? I haven't done that, but it's a hunch.