screencast-capture icon indicating copy to clipboard operation
screencast-capture copied to clipboard

Question : listening to global keyboard input (in-game)

Open bigworld12 opened this issue 9 years ago • 2 comments

first thanks for this awesome program and your efforts to keep it awesome :)

second i have been facing some problems trying to make a global keyboard hook that listens to games (like bf3) but it just doesn't work -it works in winforms, wpf applications only- may i ask where is the class you use to install such a global keyboard hook ?

bigworld12 avatar May 04 '15 05:05 bigworld12

Hi there, thanks for the positive feedback!

The hook is installed at line 151 of file NativeKeybardContext:

  • https://github.com/cesarsouza/screencast-capture/blob/master/Sources/Native/Context/NativeKeyboardContext.cs#L151

Line 154 installs a hook to call the method lowLevelKeyboardProcHook at line 161:

  • https://github.com/cesarsouza/screencast-capture/blob/master/Sources/Native/Context/NativeKeyboardContext.cs#L161

and then the keys are passed to the rest of the application.

The SetWindowHook function is defined at the file SafeNativeMethods on line 178:

  • https://github.com/cesarsouza/screencast-capture/blob/master/Sources/Native/SafeNativeMethods.cs#L178

The problem is that this function may not be low-level enough to intercept DirectX/DirectInput calls. Depending on the game, it may be necessary to do something differently, like interacting with DirectX directly. There are some libraries that can help us with that:

  • http://stackoverflow.com/questions/3223406/low-level-mouse-hook-and-directx

Hope it helps, if you make some progress in this direction, please let me know!

Regards, Cesar

cesarsouza avatar May 04 '15 06:05 cesarsouza

first of all thanks , the whole problem was "Run as administrator" , yes actually all the libraries work , they aren't just run as administrator (i recommend using this http://tutplusplus.blogspot.ro/2010/10/ultimate-keylogger-lesson-1-global.html )

bigworld12 avatar May 05 '15 18:05 bigworld12