Does anyone know of an easy way of creating a system wide mouse or keyboard hook other than me writing it in C/C++ then implementing JNI?
Cause that seems like a lot of work just for a global hook :/
Thanks,
Chris
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Does anyone know of an easy way of creating a system wide mouse or keyboard hook other than me writing it in C/C++ then implementing JNI?
Cause that seems like a lot of work just for a global hook :/
Thanks,
Chris
Morning Chris,
What do you mean by a system wide mouse or keyboard hook?
Could you please give me an example of what you are tying to archive?
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
A mouse hook for example tracks all the mouse events. System wide because I don't want to limit it to say my application, such as a MouseListener would do...if that makes sense?
Chris
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
Well I have looked to no avail. When I get home I might have a look into writing a C Win32 Hook and linking with JNI. Once I've done that I'll make it all readily avaliable to everyone who wants it. Since it is quite common.
Chris
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
Hey JavaPF. I've tried to get started, I have developed the basic hook in C using Win32, however I need to get a quick understanding of JNI. When I use
javah -jni -classpath <class location> <class>
It seems to run flawlessly but does not produce the required .h file. This is my main problem at the moment, once I have got that then I need to try and get C++ to compile down to a god damn DLL, which is proving more work than expected
Anyhelp with the JNI header generation would be great.
Thanks,
Chris
Hey Chris,
I have very little experience with JNI. Do you use the Eclipse IDE?
This looks useful:
http://www.cs.umanitoba.ca/~eclipse/8-JNI.pdf
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
I haven't found a method of executing custom commands from with the Eclipse IDE or NetBeans, So i was using the commandline. That link you gave appears to point to thin air hehe, so it's not overly useful. Maybe it's just college Filters/Blocks/Proxies messing with it, so i'll try when I get home.
Thanks very much though,
Chris
That link is working fine for me.
Take a look at this:
http://www.javaprogrammingforums.com...s-eclipse.html
I know its not the same thing but I think you can execute custom commands somewhere here.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
I've now migrated to notepad and command prompt, and at last progress! I've had to ditch all the high level IDEs lol, ah well it's all good .
Anyways, I just wanted to tell you that I have now begun the full coding of the system, so I hope to keep you updated with progress and code.
Can I ask, is there any functionality that you would like me to add? As I don't know how much you know about C++ and JNI so I figure I could add them in at the start.
Thanks,
Chris
Just wanted to give you an update, I haven't had much chance to get to work on this due to college exams. But I am now in the middle of my exams and will be finished at the end of next week. So hopefully I will be able to dig out old code and go back over this and finish it off and get the code to you
Also i'd like to produce a sample macro'ing program using it and the Robot API, which should be quite nice.
Regards,
Chris
Sounds good Chris I know it will come in very useful. Keep me updated..
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
I doubt this is possible in java since it runs off of a Vm. I could be wrong though.
Last edited by Fendaril; June 14th, 2009 at 11:27 PM.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
Just for the record it's not complex, its just a god damn stupid with UnsatisfiedLinker error, so its hard to even test things, I don't even know why it is doing that to me -_-
Chris
I finally found out what the problem was
I was forgetting to compile it as if it were C code rather than C++, cause C doesn't name mangle like C++ does lol!
Chris
ok ok. Now this one is not so much a programming problem, I just want some help with a bit of logic. For the keyboardhook, I've decided what information to proccess, what key is pressed, is the alt key pressed and is it an extended key, plus was it a keyup or keydown.
However for the mouse, there are a fair few different states that need to be proccessed, 9 in actually fact. Now If I do this in C/C++ its not to hard because they have nice names like WM_LMBUTTONDOWN but, then there are a whole list of different things they could be true such as ctrldown and shift downand any other mouse button down. So there would be alot of possibles combinations, which would get messy sending the data back to Java. But if I was to do it in Java i'd have to find out a long list of numbers. So basically, I need to know what key data I should procces in C++ and send to Java, my suggestion is as Follows.
Which button
Up or Down
is ctrl pressed
is shift pressed
x pos
y pos.
Thanks,
Chris