Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8868089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:11:00+00:00 2026-06-14T17:11:00+00:00

IS there a way to catch all keyboard and mouse events from all applications

  • 0

IS there a way to catch all keyboard and mouse events from all applications running on Windows using .NET?

I’ve found some similar posts, the first being how to do this just for the application you are developing: VB Detect Idle time

As well as a post showing how to find how long the desktop has been idle: Check whether user is inactive

What I tried is below, basically using a timer in my main form that calls GetInactiveTime every 10 seconds and I record that time, then when CurrentInactiveTime < LastInactiveTime I raise an event. What I’m looking for is something that would be a little more real time and a little more precise.

<StructLayout(LayoutKind.Sequential)> _
Public Structure LASTINPUTINFO
    Public cbSize As UInteger
    Public dwTime As UInteger
End Structure

<DllImport("user32.dll")> _
Friend Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
End Function

Public Shared Function GetInactiveTime() As TimeSpan
    Dim info As LASTINPUTINFO = New LASTINPUTINFO()
    info.cbSize = CUInt(Marshal.SizeOf(info))

    If GetLastInputInfo(info) Then
        Return TimeSpan.FromMilliseconds(Environment.TickCount - info.dwTime)
    Else
        Return Nothing
    End If
End Function

Sub Main()
    inactiveTimer = New Timer()
    inactiveTimer.Interval = 10000
    inactiveTimer.Enabled = True
    inactiveTimer.Start()

    Dim tempTime As DateTime = Now
    lastInactiveTime = tempTime - tempTime
End Sub

Private Sub inactiveTimer_Tick(sender As Object, e As EventArgs) Handles inactiveTimer.Tick
    Dim currentInactiveTime As TimeSpan = GetInActiveTime()
    Dim tempLastInactiveTime As TimeSpan = lastInactiveTime

    lastInactiveTime = currentInactiveTime

    If currentInactiveTime < tempLastInactiveTime Then
         RaiseEvent SomeEvent
    End IF
End Sub

Also, I’m programming in a Windows/VB.NET environment.

Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:11:02+00:00Added an answer on June 14, 2026 at 5:11 pm

    I’ve used this solution to the very same problem. It’s code I found on the net, but I’ve adapted it to my needs.

    You should be able to drop this into your code window and modify it as needed.

    Public Structure LASTINPUTINFO
        Public cbSize As Int32
        Public dwTime As Int32
    
    End Structure
    
    Declare Function GetLastInputInfo Lib "User32.dll" (ByRef plii As LASTINPUTINFO) As Boolean
    
    Private Sub IdleTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IdleTimer.Tick
    
    
        If ReportingEntireClass = False Then
            Dim LII As New LASTINPUTINFO, TicksSinceLastInput As Int32 = 0
    
            LII.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(LII)
    
            If GetLastInputInfo(LII) Then TicksSinceLastInput = (Environment.TickCount - LII.dwTime)
    
            If TicksSinceLastInput >= IdleSeconds Then
                If IdleClosing = False Then
                    IdleClosing = True
                    Idle.ShowDialog() 'this is a little 
                                      'form that warns about the app closing.
                End If
            End If
        End If
    
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to catch all events from a specific object? When I
I'm using C# and Caliburn. Is there a global way to catch all exceptions
Is there a way for me to catch all incoming requests to my ASP.NET
Is there a way to catch all keyboard input in a browser? Im guessing
Is there a way to catch all gui events like button clicked, text changed,
In Java, is there any way to get (catch) all exceptions instead of catching
Is there some way I can catch when a method generates a write to
Is there way to get file from windows xp command prompt? I tried to
Is there any way to catch all the excepions within an application at Main()
Is there a way to automatically catch all (unchecked) exceptions thrown by BlazeDS remoting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.