Results 1 to 5 of 5

Thread: Detect Keystroke & Mouse Movement

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Detect Keystroke & Mouse Movement

    hi guys help please..I want to create a windows application that would detect if there is any activity in my computer like keystroke & mouse movement but i want the windows application to be hidden...Can you give me guys an idea on how to do this? like what should I use to detect the mouse movement or keystroke. Thanks in advance guys!

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Detect Keystroke & Mouse Movement

    Are you writing a keylogger program?

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Detect Keystroke & Mouse Movement

    Nope. Take note...I just want to detect if there is any activity, I dont say that I want to get the characters/keys that have been pressed. actually, what im trying to do here is that, I want my windows application to detect any activity(mouse movement or keystroke) in my computer and if there are no any activities in span of time it will automatically lock my workstation. Hope you get my point. Dont worry im not on to something that would harm my user.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Detect Keystroke & Mouse Movement

    you can use GetLastInputInfo API to get the time since the last input (keyboard/mouse) was received by Windows. Use a timer and call this function to get the user idle time (in milliseconds)
    This code was copied from Experts-exchange at this link
    http://www.experts-exchange.com/Prog..._21504813.html
    Code:
    using System;
    using System.Runtime.InteropServices; 
    
    namespace OperatingSystem.API
    {
    
      public class Idle 
      { 
    
        [DllImport("User32.dll")] 
        private static extern bool GetLastInputInfo(
          ref LASTINPUTINFO lastInput); 
    
    
        [StructLayout(LayoutKind.Sequential)] 
          public struct LASTINPUTINFO 
        { 
          public Int32 cbSize; 
          public Int32 dwTime; 
        } 
    
    
        public int IdleTime 
        { 
          get 
          { 
    
            LASTINPUTINFO lastInput = new LASTINPUTINFO(); 
            lastInput.cbSize = Marshal.SizeOf(lastInput); 
    
            int idle = 0;
    
            if (GetLastInputInfo(ref lastInput)) 
              idle = (Environment.TickCount - lastInput.dwTime) / 1000;
    
            return idle; 
          } 
        } 
      }
    
    }

  5. #5

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Detect Keystroke & Mouse Movement

    Thanks for that Stanav! I'll give it a try..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width