Soru & Cevap

C# ...

01.07.2015 - 11:06

Arkadaşlar c# da klavye ve fare kullanılmadığı zamanı gösteren uygulama yapmam gerek yardımcı olur musunuz ? 

 

55 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-56464-1435045119.jpg
ghost_man
01.07.2015 - 12:15

Buldum Arkadaşlar belki sizede lazım olur diye atıyorum buraya 

using System;
using System.Runtime.InteropServices;
using System.Timers;

public struct LastInputInfo
{
    public uint cbSize;
    public uint dwTime;
}

public class Program
{
    [DllImport("user32.dll")]
    static extern bool GetLastInputInfo(ref LastInputInfo plii);

    static LastInputInfo info = new LastInputInfo();

    public static TimeSpan GetInactiveTime()
    {
        if (GetLastInputInfo(ref info))
            return TimeSpan.FromMilliseconds(Environment.TickCount - info.dwTime);
        else
            return TimeSpan.Zero;
    }

    static void Main(string[] args)
    {
        info.cbSize = (uint)Marshal.SizeOf(info);

        Timer t = new Timer(1000);
        t.Start();
        t.Elapsed += delegate { Console.WriteLine(GetInactiveTime().ToString()); };

        Console.ReadLine();
    }
}