[英]Keylogger-like application in C# to record time-stamps for application start and end
My main goal is to record the "total time" a user spends on an application. 我的主要目标是记录用户在应用程序上花费的“总时间”。 I want to create a background agent in Windows that would be installed on a client PC.
我想在Windows上创建将安装在客户端PC上的后台代理。 This agent is like a keylogger and sits in the background and records the following:
该代理就像键盘记录程序一样,位于后台并记录以下内容:
My challenges are: 我的挑战是:
Any help would be deeply appreciated. 任何帮助将不胜感激。
I've writen an Keylogger API in C# that can hook any key pressed by the user and mouse clicks. 我已经用C#写了一个Keylogger API,它可以钩住用户按下的任何键以及鼠标单击。 When one of these events occurs the API returns a callback containing an object that says which key was pressed and WHAT SCREEN THE USER WAS.
这些事件之一发生时,API将返回一个回调,该回调包含一个对象,该对象说明按下了哪个键以及用户在哪个屏幕上进行了操作。 The same for the mouse click, in wicht it returns where the user have clicked and WHAT SCREEN THE FOCUS WAS IN THAT MOMENT.
鼠标单击也是如此,它会返回用户单击的位置以及那一刻的焦点所在。
In my API this is the method that I use to get the focused screen, you can adapt for your needs: 在我的API中,这是我用来获取焦点屏幕的方法,您可以适应您的需求:
private static string CurrentWindowTitle()
{
int hwnd = GetForegroundWindow();
StringBuilder title = new StringBuilder(1024);
int textLength = GetWindowText(hwnd, title, title.Capacity);
if ((textLength <= 0) || (textLength > title.Length))
return "[Unknown]";
return $"[{title}]";
}
The methods GetForegroundWindow()
and GetWindowText()
are just methods of the User32.dll: 方法
GetForegroundWindow()
和GetWindowText()
只是User32.dll的方法:
[DllImport("User32.dll")]
internal static extern int GetForegroundWindow();
[DllImport("User32.dll")]
internal static extern int GetWindowText(int hwnd, StringBuilder s, int nMaxCount);
The source code of the API that I've mentioned can be foud here 我提到的API的源代码可以在这里找到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.