vb.net winform实现窗体空闲时间的检测

功能:如果在指定时间内,用户没有进行鼠标和键盘的操作,则认定空闲,从而进行响应操作
Public Class frmSetting
    Implements IMessageFilter
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Application.AddMessageFilter(Me)
    End Sub
    Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
        '==Retrigger timer on keyboard and mouse messages
        If (m.Msg >= &H100 And m.Msg <= &H109) Or (m.Msg >= &H201 And m.Msg <= &H209) Then
            'Do your action
        End If
        Return False
    End Function
所有鼠标以及键盘的操作信息都会先进入PreFilterMessage方法,注意此函数若是返回True,则此消息将不会被发送到相应的事件,即事件被屏蔽了

关于Mouse input 和 Keyboard input 的m.Msg的值分别代表什么意义,我从微软官网摘抄下来了

大家可以选择自己需要监控信息
WM_CAPTURECHANGED               0x0215     
WM_LBUTTONDBLCLK                0x0203
WM_LBUTTONDOWN                  0x0201
WM_LBUTTONUP                    0x0202
WM_MBUTTONDBLCLK                0x0209
WM_MBUTTONDOWN                  0x0207
WM_MBUTTONUP                    0x0208
WM_MOUSEACTIVATE                0x0021
WM_MOUSEHOVER                   0x02A1
WM_MOUSEHWHEEL                  0x020E
WM_MOUSELEAVE                   0x02A3
WM_MOUSEMOVE                    0x0200
WM_MOUSEWHEEL                   0x020A
WM_NCHITTEST                    0x0084
WM_NCLBUTTONDBLCLK              0x00A3
WM_NCLBUTTONDOWN                0x00A1
WM_NCLBUTTONUP                  0x00A2
WM_NCMBUTTONDBLCLK              0x00A9
WM_NCMBUTTONDOWN                0x00A7
WM_NCMBUTTONUP                  0x00A8
WM_NCMOUSEHOVER                 0x02A0
WM_NCMOUSELEAVE                 0x02A2
WM_NCMOUSEMOVE                  0x00A0
WM_NCRBUTTONDBLCLK              0x00A6
WM_NCRBUTTONDOWN                0x00A4
WM_NCRBUTTONUP                  0x00A5
WM_NCXBUTTONDBLCLK              0x00AD
WM_NCXBUTTONDOWN                0x00AB
WM_NCXBUTTONUP                  0x00AC
WM_RBUTTONDBLCLK                0x0206
WM_RBUTTONDOWN                  0x0204
WM_RBUTTONUP                    0x0205
WM_XBUTTONDBLCLK                0x020D
WM_XBUTTONDOWN                  0x020B
WM_XBUTTONUP                    0x020C
WM_GETHOTKEY                    0x0033
WM_SETHOTKEY                    0x0032
WM_ACTIVATE                     0x0006
WM_APPCOMMAND                   0x0319
WM_CHAR                         0x0102
WM_DEADCHAR                     0x0103
WM_HOTKEY                       0x0312
WM_KEYDOWN                      0x0100
WM_KEYUP                        0x0101
WM_KILLFOCUS                    0x0008
WM_SETFOCUS                     0x0007
WM_SYSDEADCHAR                  0x0107
WM_SYSKEYDOWN                   0x0104
WM_SYSKEYUP                     0x0105
WM_UNICHAR                      0x0109


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页