[JNI] Catch Ctrl+Mouseclick on Windows?

W

watzlaw wutz

I currently work on a kind of gpl-clone of www.bablylon.com, which is
implemented in java. To embed my application into windows i need to
register hotkeys together with mouse-clicks. I want to start my
application to work if the user e.g. presses Ctrl and clicking with the
mouse. This is easy as long the application has the focus. If this is
not the case i think it is only possible using JNI.
Unfortunately (i am a more or less c++newbie and) i can't find any free
libary which would help me. There is only http://www.jniwrapper.com,
which seems to handle tasks like this, but it is commercial and i don't
think that i could get their agreement to use their libary in a
gpl-licensed software (also with buying a lisence).
So i would be very, very happy if someone of you could give me an idea
of how to create my the .dll and do the communication with java. It
would also help me a lot if you could me send some links, because i
didn't find much using google about java-jni-hotkeys-with-mouseclicks.

Please excuse my bad english. :)

greetings,
Holger Brandl
 
Y

Yu SONG

watzlaw wutz said:
I currently work on a kind of gpl-clone of www.bablylon.com, which is
implemented in java. To embed my application into windows i need to
register hotkeys together with mouse-clicks. I want to start my
application to work if the user e.g. presses Ctrl and clicking with the
mouse. This is easy as long the application has the focus. If this is
not the case i think it is only possible using JNI.
Unfortunately (i am a more or less c++newbie and) i can't find any free
libary which would help me. There is only http://www.jniwrapper.com,
which seems to handle tasks like this, but it is commercial and i don't
think that i could get their agreement to use their libary in a
gpl-licensed software (also with buying a lisence).
So i would be very, very happy if someone of you could give me an idea
of how to create my the .dll and do the communication with java. It
would also help me a lot if you could me send some links, because i
didn't find much using google about java-jni-hotkeys-with-mouseclicks.

Please excuse my bad english. :)

greetings,
Holger Brandl

You'd better look for a "hotkeys-with-mouseclicks" solution purely written
in C/C++ (plenty on the web),
and then convert it into JNI by yourself.

If I were you, I would write a windows interface in C/C++ and run the java
code in the dark background.
 
P

Pasturel

watzlaw wutz a écrit:
I currently work on a kind of gpl-clone of www.bablylon.com, which is
implemented in java. To embed my application into windows i need to
register hotkeys together with mouse-clicks. I want to start my
application to work if the user e.g. presses Ctrl and clicking with the
mouse. This is easy as long the application has the focus. If this is
not the case i think it is only possible using JNI.
Unfortunately (i am a more or less c++newbie and) i can't find any free
libary which would help me. There is only http://www.jniwrapper.com,
which seems to handle tasks like this, but it is commercial and i don't
think that i could get their agreement to use their libary in a
gpl-licensed software (also with buying a lisence).
So i would be very, very happy if someone of you could give me an idea
of how to create my the .dll and do the communication with java. It
would also help me a lot if you could me send some links, because i
didn't find much using google about java-jni-hotkeys-with-mouseclicks.

Please excuse my bad english. :)

greetings,
Holger Brandl
I did this kind of JNI programm.
Under Windows, i use the GetAsyncKeyState functiun but it's not obvious
to understand how it works .
See piece of my JNI function below :

unsigned int nlist[] = {1,2,3,8,9,12,13,19,20,27,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,

57,58,59,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,91,93,96,97,98,99,100,
101,102,103,104,105,106,107,108,109,110,111,112,113,
114,115,116,117,118,119,120,121,122,123,124,125,126,
127,128,129,130,131,132,133,134,135,136,137,138,139,
140,141,142,143,144,145,146,147,148,149,150,151,152,
153,154,155,156,157,158,159,
166,167,168,169,170,171,172,173,174,175,176,177,178,
179,180,181,182,183,184,185,186,187,188,189,190,191,
192,193,194,195,196,197,198,199,200,201,202,203,204,
205,206,207,208,209,210,211,212,213,214,215,216,217,
218,219,220,221,222,223,224,225,226,227,228,230,233,
234,235,236,237,238,239,240,241,242,243,244,245,246,
247,248,249,250,251,252,253,254,255,0};
long key=0;


JNIEXPORT jlong JNICALL Java_RobotSaisieJLPV4_KeyLogJava_keytyped
(JNIEnv *env, jobject obj)
{ ....
jlong key=0;
for(i = 0;nlist != 0;i++)
{
if (GetAsyncKeyState(nlist)== -32767)

{
break;
}
}


//if(nlist == 0)
// continue;
//else
key=nlist;
if ( key == 1)
{
printf("appuye sur bouton gauche\n");
}
if ( key == 2)
{
printf("appuye sur bouton droit\n");
}
if ( key == 4)
{
printf("appuye sur bouton milieu\n");
}
//vrai=0;
//}
//printf("Sortie de boucle key= %d ; retour=%d\n",key,retour);
// on retourne si aucune touche n'est detectee appuyee
if (key == 0) return 0;

// test si la touche shift est appuyee
if (key == 0) return 0;
if ( GetAsyncKeyState(16) == -32767 || GetAsyncKeyState(16) == -32768)

{
isShift=1;
}
//test si la touche control est appuyee
if ( GetAsyncKeyState(17) == -32767 || GetAsyncKeyState(17) == -32768)

{
isControl=1;
}
//test si la touche Alt est appuyee
if ( GetAsyncKeyState(18) == -32767 || GetAsyncKeyState(18) == -32768)

{
isAlt=1;
}
//construction du code retour
key=1000000+ ((jlong)(isShift)) * ((jlong)100000)+((jlong)
(isControl))*((jlong) 10000)+((jlong)(isAlt))*((jlong) 1000) +((jlong)
nlist);

printf("key= %ld\n",key);

return ((jlong) key) ;
}


Hope it helps you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top