开发者

How to get notified of mouse/keyboard activity without a global hook?

I have a transparent window (WS_EX_TRANSPARENT) floating topmost.

Whenever there is a mouse move (anywhere on开发者_如何学JAVA the screen) or keyboard stroke, it needs to display the related info (e.g. mouse position).

Is it possible to capture mouse/keyboard activities without using a global hook? Anti-virus software almost always triggers false alarms for the use of global hooks.

Any idea greatly appreciated.


I guess, GetAsyncKeyState and GetCursorPos might help. You probably can have a thread calling these functions every 300-500 msec, and posting a message to your main thread.


You could register for receiving raw input messages via RegisterRawInputDevices. Have a look over here, there are some links in the accepted answer of RRUZ, one points to a C# implementation. This works with window messages, no hooks involved.

(With this method you also get information about the specific device the input came from, so you could distinguish between multiple keyboards. That's where most questions having "use RegisterRawInputDevices" as answer are heading. But you can also use it to just capture the input, not caring about the source.)


You can get notified of keyboard/mouse activity (GetLastInputInfo), and I am fairly certain you can get the cursor position (GetMouseMovePointsEx). If you do not need the actual keyboard strokes, then that should do it. If you do, I do not think it can be done...


LASTINPUTINFO lastInputInfo = new LASTINPUTINFO(); UInt32 lastInputTick = lastInputInfo.dwTime; return Environment.TickCount - (Int32)lastInputInfo.dwTime

This code (C#) return the inactivity time (keyboard and mouse both). So you can have the time since the user is inactive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜