using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; //导入命名空间 using System.Runtime.InteropServices; namespace WebAppLock { public partial class WebForm1 : System.Web.UI.Page { [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] public static extern int GetKeyState(int Key); protected void Page_Load(object sender, EventArgs e) { if ((GetKeyState(20) & -1) > 0) { Label1.ForeColor = System.Drawing.Color.Red; Label1.Text = "大写琐打开"; } else { Label1.Text = ""; } } } }
这样可以显示,但是只有一次,后来我在控件上加了autopostback,要好一点,基本实现,但是需要刷新页面.
我不知道大家有没有别的办法!我现在只能做到这一步!
改自:
http://blog.youkuaiyun.com/yzhxhwt/archive/2007/08/02/1721960.aspx
检测大写锁定
本文介绍了一个使用C#在Web应用程序中检测键盘大写锁定状态的方法。通过调用GetKeyState API函数并结合ASP.NET页面事件,实现了大写锁定状态的变化显示。
键打开功能&spm=1001.2101.3001.5002&articleId=81972877&d=1&t=3&u=36285f347e914e7fb82bae79693a981c)
4178

被折叠的 条评论
为什么被折叠?



