5

I want to be able to record mouse movements, clicks and keyboard input from a user. It would be great if it was a cross platform solution.

I'd like to get back something like this (pseudo code):

mouse moved to 500, 500 mouse double clicked mouse moved to 800, 300 mouse left clicked keyboard typed "Hello World"

Does either C++ or Java have any classes that can do this? If I was using C++, I would probably working with the QT framework.

Edit:

I should have said this originally, but I want to record the movements and clicks outside of the applications gui, so on the desktop too.

Joe
  • 4,553
  • 9
  • 51
  • 57
  • 2
    Do you need to record system-wide input or just in your application's main window? – finnw Feb 09 '10 at 23:07
  • see this similar question : http://stackoverflow.com/questions/2147903/retrieve-window-handle-and-press-button-programatically – lsalamon Feb 09 '10 at 23:38

5 Answers5

0

GLUT does this, but it's tied to OpenGL which might be overkill for your project.

OpenGL is cross-platform.

Robert Greiner
  • 29,049
  • 9
  • 65
  • 85
  • Or freeglut (http://freeglut.sourceforge.net/) which is actively maintained unlike GLUT which was abandoned more than 10 years ago – Manuel Feb 09 '10 at 23:42
0

I don't believe there's a cross-platform toolkit specifically for grabbing input from a window and nothing more, but most toolkits provide this capability. Two good options are:

  1. Use SDL, as it's fairly lightweight and can handle simple input.
  2. Implement the functionality natively per platform, as it should be trivial in X11, Windows, Mac OS X, etc.
Joey Adams
  • 41,996
  • 18
  • 86
  • 115
0

If you want to trap events across the whole GUI system, not just one app, there's not much likelihood of a cross platform solution. However, the event hooking part could easily be separated from the recording part, so you could make most of the program cross-platform.

For Windows, you need this 17 year old (!) document. (Man, I'm getting old!)

Daniel Earwicker
  • 114,894
  • 38
  • 205
  • 284
0

On Windows, this is called a Journal Record Hook. You should write the hook part in C or C++, it might be technically possible to do in java, but it's not a good idea, you want your hook procedure to have as few dependencies as possible, and to be a quick as possible. System wide hooks, especially journal add a lot of overhead to keyboard and mouse input, you want to minized your impact as much as possible.

You Install Windows hooks by using SetWindowsHookEx passing WH_JOURNALRECORD to get a Journal Record Hook.

You could also (maybe) get this working by installing both WH_KEYBOARD_LL and WH_MOUSE_LL, but your two hook procedures would be called separately, and you would have to write your own code to put the events in order.

I doubt you will find a cross-platform solution.

John Knoeller
  • 33,512
  • 4
  • 61
  • 92
0

It sounds like Qt might allow you to implement event filters that extend beyond the application to the window system. See also Qt - top level widget with keyboard and mouse event transparency?

Community
  • 1
  • 1
TreDubZedd
  • 2,571
  • 1
  • 15
  • 20