PDA

Click to See Complete Forum and Search --> : Detect Keystroke & Mouse Movement


daimous
Oct 23rd, 2007, 04:00 AM
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!

stanav
Oct 23rd, 2007, 08:42 AM
Are you writing a keylogger program?

daimous
Oct 23rd, 2007, 06:39 PM
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.

stanav
Oct 23rd, 2007, 07:28 PM
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/Programming/Languages/.NET/Q_21504813.html

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;
}
}
}

}

daimous
Oct 23rd, 2007, 07:50 PM
Thanks for that Stanav! I'll give it a try..