Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [JNI] Catch Ctrl+Mouseclick on Windows?

Reply
Thread Tools

[JNI] Catch Ctrl+Mouseclick on Windows?

 
 
watzlaw wutz
Guest
Posts: n/a
 
      05-10-2004
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
 
Reply With Quote
 
 
 
 
Yu SONG
Guest
Posts: n/a
 
      05-10-2004
"watzlaw wutz" <(E-Mail Removed)>
> 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.

--
Song

More info.:
http://www.dcs.warwick.ac.uk/~esubbn/


 
Reply With Quote
 
 
 
 
Pasturel
Guest
Posts: n/a
 
      05-11-2004
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,10 0,
101,102,103,104,105,106,107,108,109,110,111,112,11 3,
114,115,116,117,118,119,120,121,122,123,124,125,12 6,
127,128,129,130,131,132,133,134,135,136,137,138,13 9,
140,141,142,143,144,145,146,147,148,149,150,151,15 2,
153,154,155,156,157,158,159,
166,167,168,169,170,171,172,173,174,175,176,177,17 8,
179,180,181,182,183,184,185,186,187,188,189,190,19 1,
192,193,194,195,196,197,198,199,200,201,202,203,20 4,
205,206,207,208,209,210,211,212,213,214,215,216,21 7,
218,219,220,221,222,223,224,225,226,227,228,230,23 3,
234,235,236,237,238,239,240,241,242,243,244,245,24 6,
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[i] != 0;i++)
{
if (GetAsyncKeyState(nlist[i])== -32767)

{
break;
}
}


//if(nlist[i] == 0)
// continue;
//else
key=nlist[i];
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) == -3276

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

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

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

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

return ((jlong) key) ;
}


Hope it helps you

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
catch doesn't catch a thrown exception Marteno Rodia Java 5 08-05-2009 03:30 AM
catch(...) doesn't catch everything Adam C++ 9 02-02-2006 05:02 PM
Catch pid for a process that created Mav Perl 2 08-20-2004 08:56 PM
why catch (...) can not catch such exception John Black C++ 8 08-20-2004 02:34 PM
Trace: Can anyone suggest a good tool to catch trace messages? Rukmal Fernando ASP .Net 4 10-27-2003 09:03 PM



Advertisments