Catching Global Mouse Events Java
Catching Global Mouse Events Java
- Subject: Catching Global Mouse Events Java
- From: mike cann <email@hidden>
- Date: Tue, 6 Oct 2009 16:52:58 +0100
Hi Guys,
I have been forwarded here from the JNA list by a very helpful Timothy Wall
for advice and hints from you guys.
Im attempting to capture low-level events in OSX (for now mouse events) and
then pass them to Java.
I have a very simple version of this working in C (XCode) using the Carbon
framework based on the MonitorEvents example by apple (
http://developer.apple.com/mac/library/samplecode/EventMonitorTest/)
I have uploaded this very simple working sample here:
http://www.mikecann.co.uk/DumpingGround/JNA/SimpleEventMonitorXCode.zip
My next step was to get these events in Java. I initially started to use JNI
but then I discovered JNA and decided to give that a go first as then it
would allow me to code everything in pure Java which seems like a neater
solution to me.
So after much backward and forward emailing with Tim I got to the stage
where I have a very simple JNA example that compiles and runs with no
errors: http://www.mikecann.co.uk/DumpingGround/JNA/JNAMacTest.zip
The only problem now is that im not getting any events in my Java program
and im not sure why and as there are no errors its difficult to track down
what I must be doing wrong.
The code all revolves around the Carbon InstallEventHandler() method:
// the magic happens here with the call to GetEventMonitorTarget
as described in CarbonEvents.h
// The event monitor target is a special event target used to
monitor user input events across all processes.
// When the monitor target detects a matching event, then
MonitorHandler is called.
// InstallEventHandler( GetEventMonitorTarget(), MonitorHandler,
GetEventTypeCount( kEvents ),kEvents, 0, &sHandler
); // C version
OSStatus status =
lib.InstallEventHandler(lib.GetEventMonitorTarget(), new KeyListener(), new
ItemCount(1), eventTypes, null, sHandlerRef); // JNA version
There is no error returned from this so im not sure whats going wrong.
So my question is are there any low-level debugging tools I can use to
compare what happens on the C version and the Java version?
Also there is a JNA version of the cocoa framework, but unfortunately I
couldnt find any info on global-mouse event capturing using pure cocoa, as
far as I could tell you have to use Carbon to to this?
Cheers,
--
Mike Cann
http://www.mikecann.co.uk/
http://www.artificialgames.co.uk/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden