[JNI] Catch Ctrl+Mouseclick on Windows?

Discussion in 'Java' started by watzlaw wutz, May 10, 2004.

  1. watzlaw wutz

    watzlaw wutz Guest

    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
    watzlaw wutz, May 10, 2004
    #1
    1. Advertising

  2. watzlaw wutz

    Yu SONG Guest

    "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


    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/
    Yu SONG, May 11, 2004
    #2
    1. Advertising

  3. watzlaw wutz

    Pasturel Guest

    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
    Pasturel, May 11, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny

    Implement Ctrl-C, Ctrl-V

    Danny, Aug 14, 2003, in forum: C++
    Replies:
    5
    Views:
    650
    CBFalconer
    Aug 15, 2003
  2. Danny

    Implement Ctrl-C, Ctrl-V

    Danny, Aug 14, 2003, in forum: C Programming
    Replies:
    5
    Views:
    665
    CBFalconer
    Aug 15, 2003
  3. Angus
    Replies:
    5
    Views:
    2,106
    Michael Rauscher
    Nov 18, 2006
  4. Replies:
    2
    Views:
    1,416
    Munna
    Jul 10, 2008
  5. Replies:
    0
    Views:
    557
Loading...

Share This Page