K
K
kemsky2012-07-05 23:34:34
Programming
kemsky, 2012-07-05 23:34:34

How to intercept/replace mouse/keyboard events in Windows without injection into the process?

I want to write an analogue of AutoHotKey , with the ability to write scripts in Lua and integrated AutoIt functions and possibly functions for working with the user interface.

One of the key features of AutoHotKey is key remapping. I would also like to convert some events/keyboard shortcuts to others, say sidemouse+scroll => volume control, depending on the active application.

AutoHotKey, for example, allows key remapping and uses the LL mouse/keyboard hook. Judging by msdn, these hooks are processed in the context of the program that installed the hooks. And this is very important, since antiviruses and anti-cheats can mess things up. In addition, hooks slow down the system.

It is also important to be able to filter events by device, i.e. different devices may have their own configuration. Perhaps a driver is needed?

In general, I am grateful for any ideas, thoughts on this matter.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
4
4dmonster, 2012-07-06
@4dmonster

in such statement of a question - yes, the driver is necessary.
By the way, they recently wrote on Habré habrahabr.ru/post/146071/

A
ak40u, 2012-07-08
@ak40u

Hook to do

C
Corwal, 2012-07-08
@Corwal

No matter how much I have used low-level hooks, I have never experienced any inconvenience with antiviruses. Of course, there is a load on the system, but not so significant (after all, keyboard and bear events do not occur so often as to heavily load the processor even with a not-so-optimal algorithm that solves your problem).
I also have an article on this topic:
habrahabr.ru/post/146800/

K
kemsky, 2012-07-11
@kemsky

On the one hand, hooks are a simple solution, on the other hand, there are some drawbacks. For example, Windows can throw a hook if it takes too long to execute or if it is impossible to determine the source device of the event.
The driver, in fact, is ideal only for redefining events (with primitive conditions) from a specific device, there is a ready-made version oblita.com/Interception .
Maybe I don't fully understand, but the driver won't work for me, I want to be able to execute a simple lua script in the hook (let's say check which window is active and return the corresponding code).
The sources of AutoHotKey are open, but unfortunately there is a lot of code there, you can peep something, but there is no desire to understand everything.
PS For some reason I don't see pictures in the article...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question