[英]c# keep running application without run
I was trying to implement key-logger and mouse-logger in .net.我试图在 .net 中实现键盘记录器和鼠标记录器。 So I have a class KeyLog
and MouseLog
.所以我有一个KeyLog
和MouseLog
类。 Inside both class's constructor, I have this same logic :在两个类的构造函数中,我有相同的逻辑:
MouseLog:鼠标日志:
public MouseLog()
{
_hookID = SetHook(_proc);
Application.Run();
UnhookWindowsHookEx(_hookID);
}
KeyLog :按键日志:
public KeyLog()
{
_hookID = SetHook(_proc);
Application.Run();
UnhookWindowsHookEx(_hookID);
}
I'm using Application.Run
to keep running the application.我正在使用Application.Run
来继续运行应用程序。
NB: It is a console application.注意:它是一个控制台应用程序。
Now I have another class, PLog
(Parent Log), inside that I have :现在我有另一个类, PLog
(父日志),里面有:
public PLog()
{
KeyLog();
MouseLog();
}
This PLog
is called from a Main
method.这个PLog
是从Main
方法调用的。 The problem is If I put KeyLog
before MouseLog
in PLog
, MouseLog
doesn't work, else KeyLog
doesn't work.问题是如果我把KeyLog
之前MouseLog
在PLog
, MouseLog
不能正常工作,否则KeyLog
不起作用。
I can understand the problem, that it is not getting to the next statement, because Application.Run
has already been called.我可以理解这个问题,它没有进入下一个语句,因为Application.Run
已经被调用。 How can I resolve this?我该如何解决这个问题?
I don't want to use thread as this will keep running as long as the PC runs.我不想使用线程,因为只要 PC 运行,它就会一直运行。
using System.Windows.Forms;使用 System.Windows.Forms;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.