kristian / system-hook

Global Keyboard / Mouse Hook for Java applications.
MIT License
269 stars 48 forks source link

Input key issue with Omsi 2 #7

Closed Safraann closed 8 years ago

Safraann commented 8 years ago

Hello, I try to get input keys coming from the game Omsi 2, especially one in particular: the touch 6. Everything works very well if I am on google chrome, my desktop or even in a folder, but as soon as Windows is on Omsi 2 (fullscreen mode or not), the console (in eclipse ide) indicates me nothing more :/ Thank you in advance =)

PS = My code if necessary : http://pastebin.com/3fsaYiie

Safraann commented 8 years ago

Hello, this is what I was able to adjust since the last time. Then I managed to run well the API, only it turns out that if I launch Omsi 2 either the same Photofiltre, or even Google Chrome or any other programs as administratordirector, then the console does not receive any more the inputs. Is there a solution for this ?

kristian commented 8 years ago

Hello Plaigon, not sure if I can support your here. Generally a lot of games are using low-level keyboard hooks themselfs to catch keyboard input. Or they even go "one level deeper" and use raw-input to receive keyboard events.

Generally the way low-level hooks work, is that one hook is called after another. Each hook has to call the next hook by invoking CallNextHookEx. If one hook doesn’t call CallNextHookEx, the “next” program will, for example, not get the keyboard event. Every hook should call CallNextHookEx, but especially for a game like Omnibus Simulator, I can imagine they havn't tested this all too well. So if they don't call CallNextHookEx, your hook won't get notified, because it might got registred with a lower priority.

Hook priorities are based on the order in which the hooks are installed. The hook installed latest, has the highest priority. This means you’d have to ensure that the low-level hook is installed after the game was started, to check if they actually don't call CallNextHookEx. Please do also see the KeyboardHook.c implementation.

Last but not least, if they are grabbing the input, e.g. using raw input, they might forcefully prevent other programs from getting any input events. Again bad design, but likely you won't find a way to outsmart this.

Hope this helps. Regards, Kristian