完整代码如下:
Option Explicit
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Dim lii As LASTINPUTINFO
Private Sub Form_Load()
Timer1.Interval = 1000
lii.cbSize = Len(lii)
End Sub
Private Sub Timer1_Timer()
If GetLastInputInfo(lii) Then
If (GetTickCount - lii.dwTime) / 60000 >= 15 Then
Shell "shutdown.exe -s -t 180"
Call MsgBox("由于本机15分钟没有 *** 作,如果3分钟后没有反应,系统将强制关机", vbYesNo + vbExclamation + vbDefaultButton2, "提示")
End If
End If
End Sub
1、命名空间:using System.Runtime.InteropServices
2、导入方法
[DllImport("user32.dll", EntryPoint = "GetKeyboardState")]
public static extern int GetKeyboardState(byte[] pbKeyState)
3、大小写状态
public static bool CapsLockStatus
{
get
{
byte[] bs = new byte[256]
GetKeyboardState(bs)
return (bs[0x14] == 1)
}
}
4、引用,此部分根据你的需要来修改
private void button2_Click(object sender, EventArgs e)
{
if (CapsLockStatus == true)
MessageBox.Show("键盘处于大写锁定状态!")
else
MessageBox.Show("键盘处于小写状态!")
}
不懂请HI我:)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)